Unified theory of tearing modes