Why are the first-order deformations of a scheme $X$ over a field $k$ given by $Ext^1_{\mathcal O_X}(\Omega_X,\mathcal O_X)$, where here I mean the Ext group?

Furthermore, for an integral affine scheme $Spec B$ of finite type over algebraically closed $k$, why is $T^1(B/k,M)\cong Ext^1(\Omega_{B/k},M)$ for any torsion-free $B$-module $M$?

Writing $B=A/I$, where $A=k[x_1,...,x_n]$, we get an exact sequence, $0\rightarrow Hom(\Omega_{B/k},M)\rightarrow Hom(\Omega_{A/k}\otimes B,M)\rightarrow Hom(I/I^2,M)\rightarrow T^1(B/k,M)\rightarrow 0$. Since the $T^i$ functors commute with localization, we can localize to a principal open set, say $D(f)$, contained inside the dense open nonsingular locus of $Spec B$. But there the conormal exact sequence $I/I^2\rightarrow \Omega_{A/k}\otimes B\rightarrow \Omega_{B/k}\rightarrow 0$ is left exact as well, and the corresponding exact sequence for the $T^i$ functors is precisely the same long exact sequence obtained by applying $Hom(--,M)$ to the now left exact conormal sequence. Thus $T^1(B/k,M)= Ext^1(\Omega_{B/k},M)$ over $D(f)$. So my real question is why does this imply the result before localization? I suspect it has something to do with $M$ being torsion-free, but I'm not sure how to finish the argument.

These seem to be basic facts in Deformation theory, but I can't find a proof of them.

Thanks