Show that $\ker(f)$ is finitely generated, when $f: M \rightarrow A^n$ is a surjective $A$-module homomorphism and $M$ is finitely generated This is the problem I am attempting:

Let $M$ be a finitely generated $A$-module and $f: M \rightarrow A^n$ a surjective homomorphism. Show that $\ker(f)$ is finitely generated. 

Following a hint in the book and from another question here, I'm confident I have shown that $M$ is a direct sum of $\ker(f)$ and the set of $u_i$ ($i=1,\dots,n$) where $f(u_i)=e_i$ and the set of $e_i$ generates $A^n$, and I know that if $z$ is an element of $\ker(f)$, and $x_1, x_2, ..., x_m$ are a generating set for $M$, I can write $x_i - (a_{i1}u_1 + a_{i2}u_2 + \cdots + a_{in} u_n) \in \ker(f)$ for each i from 1 to m, and $z = b_1x_1 + b_2x_2 + \cdots + b_mx_m$. This is where I'm stuck: I would like to say that $y_i := x_i - (a_{i1}u_1 + a_{i2}u_2 + \cdots + a_{in}u_n)$ is a set of elements of $\ker(f)$ and somehow create a generating set for $\ker(f)$ using the fact with $z$ above and the set of $y_i$'s, but I'm not sure of any valid way to do it. 
(Note that every instance of $a_i$ or $b_i$ is an element of $A$ in the above)
 A: The abstract way: given that $M = \ker(f) \oplus N$ (here $N$ is the submodule of $M$ generated by the $u_i$), we have a projection $M \twoheadrightarrow \ker(f)$, so $\ker(f)$ is finitely generated (if there is a surjection $M \xrightarrow{\phi} M'$, and $x_1, ..., x_m$ generate $M$, then $\phi(x_1),...,\phi(x_m)$ will generate $M'$).
If you want to see it explicitly though: if $x_1,...,x_m$ generate $M$, write $x_i = z_i + n_i$ for each $i$, where $z_i \in \ker(f)$ and $n_i \in N$. Given any $z \in \ker(f)$, write $z = \sum a_ix_i = (\sum a_iz_i) + (\sum a_in_i)$. Then $z - (\sum a_iz_i) = (\sum a_in_i) \in \ker(f) \cap N = 0$, so $z = \sum a_iz_i$, hence $z_1, ..., z_m$ generate $\ker(f)$.
A: Since $A^n$ is projective (because it's free), any epimorphism to it splits, in the sense that, in your notation, there exists a morphism $g\colon A^n\to M$ such that $fg$ is the identity. Then $M=\ker f\oplus\operatorname{im} g$ and therefore $\ker f$ is finitely generated, being in turn an epimorphic image of $M$.
