Concluding that a finitely generated module is free? Suppose $R$ is a local Noetherian domain, and $M$ is a finitely generated $R$-module. Furthermore, let's suppose there exists $k>0$ such that
$$
\dim_{R_\mathfrak{p}/\mathfrak{p}R_\mathfrak{p}}M_\mathfrak{p}/\mathfrak{p}M_\mathfrak{p}=k
$$ 
for any prime $\mathfrak{p}\in\operatorname{spec}(R)$.
I've been curious though, how does this imply that $M$ is in fact a free module? I figure you want to extract some basis for $M$ from a generating set $\{x_1,\dots,x_n\}$, and this is where the dimension condition comes in. However, after localizing at $\mathfrak p$ and taking quotients, I'm losing sight of how to connect to the two ideas. 
Can someone explain why $M$ is free here? Thank you.

Let $m \subset R$ be the unique maximal ideal of the Noetherian ring. By hypothesis, $M/mM$ has dimension $k$ as an $R/m$ vector space. So, let $x_1 + mM, ..., x_k +mM$ be a basis for $M/m$. Then one can show using Nakayama's lemma (see proposition 2.8 in Atiyah-Macdonald) that $M = <x_1,...,x_k>$.
Let $p \in Spec(R)$. Then $M_p/pM_p$ is generated by $\{\frac{x_1}{1} + pM_p, ..., \frac{x_k}{1} + pM_p\}$ as a $R_p/pR_p$ module, hence is a basis for $M/pM_p$.
Let $r_1x_1 + ... + r_kx_k = 0$ in $M$ $(r_i \in R)$. Then, for all $i$, $\frac{r_i}{1} + pR_p = 0$ in $R_p/pR_p$. Thus, $\frac{r_i}{1} \in pR_p$. Hence, $r_i \in p$. But, $p$ was an arbitrary prime ideal, and since $R$ is a domain $(0)$ is prime. So, $r_i \in (0)$, and we are done.
