Abstract
We prove that, under some mild conditions, a two dimensional $p$-adic Galois representation which is residually modular and potentially Barsotti-Tate at $p$ is modular. This provides a more conceptual way of establishing the Shimura-Taniyama-Weil conjecture, especially for elliptic curves which acquire good reduction over a wildly ramified extension of $\mathbb Q_3$. The main ingredient is a new technique for analyzing flat deformation rings. It involves resolving them by spaces which parametrize finite flat group scheme models of Galois representations.