As the title states, I'm going over a proof of the following statement
Let $R$ be a commutative ring and $M$ a free $R$-module. If $\mathcal{B}_1, \mathcal{B}_2$ are two bases of $M$, then $|\mathcal{B}_1| = |\mathcal{B}_2|$.
The proof goes as follows: since $\mathcal{B}_1$ and $\mathcal{B}_2$ are two bases for $M$, we have that
$$ R^{(\mathcal{B}_1)} \simeq M \simeq R^{(\mathcal{B}_2)} $$
and so there exist $A_1, A_2 \in R^{(\mathcal{B}_1 \times \mathcal{B}_2)}$ such that $A_1A_2 = 1$ and $A_2A_1 = 1$. Now, let $m \subseteq R$ be a maximal ideal of $R$, and let $\mathbb{k} := R/m$ which is a field since $R$ is commutative.
If we now consider $\pi : R \to \mathbb{k}$ the projection to the quotient, this induces a ring morphism $\tau : R^{(\mathcal{B}_1 \times \mathcal{B}_2)} \to \mathbb{k}^{(\mathcal{B}_1 \times \mathcal{B}_2)}$ and we have that:
$$\tau(A_1)\tau(A_2) = 1 = \tau(A_2)\tau(A_2)$$
and thus $\mathbb{k}^{(\mathcal{B}_1 \times \mathcal{B}_2)}$ has an invertible element which implies $\mathbb{k}^{(\mathcal{B}_1)} \simeq \mathbb{k}^{(\mathcal{B}_2)}$, which in turn proves that $|\mathcal{B}_1| = |\mathcal{B}_2|$ because the latter is a $\mathbb{k}$-vector space isomorphism.
I mostly understand this argument except for a key point, which is going from an invertible element of $ \operatorname{Hom}_R(R^{(\mathcal{B}_1)},R^{(\mathcal{B}_2)})$ to an invertible element of $R^{(\mathcal{B}_1 \times \mathcal{B}_2)}$ and again from an invertible element of $\mathbb{k}^{(\mathcal{B}_1 \times \mathcal{B}_2)}$ to an invertible element of $ \operatorname{Hom}_{\mathbb{k}}(\mathbb{k}^{(\mathcal{B}_1)},\mathbb{k}^{(\mathcal{B}_2)})$. How is this justified?