Module over PID is isomorphic to the direct sum of a submodule and the kernel of a module homomorphism I'm reviewing some module theory before I take an algebra prelim at my university, and I came across a question that I do not know how to start.
"Let $R$ be a PID and let $M$ be an $R$-module. If $f:M\rightarrow R$ is a module homomorphism, show there exists a submodule $N$ of $M$ such that $M=N\oplus \ker(f)$."
My background with modules is limited. How can I approach this proof?
 A: First note that the image of $M$ under $f$ is an ideal of $R$; since $R$ is PID, this ideal is principal generated by an (assume non-zero) element $a\in R$.
Thus we get a surjective $R$-module homomorphism $f:M\to aR$.
Since $aR\cong R$ is a (free, hence) projective $R$-module, the exact sequence
$$\{0\}\to\operatorname{Ker}f\hookrightarrow M\xrightarrow f aR\to\{0\}$$
splits.
Consequently, $\operatorname{Ker}f$ is a direct summand of $M$.
More explicity, let $x_0\in M$ such that $f(x_0)=a$ and $N=x_0R\subseteq M$.
Then clearly $N\cap\operatorname{Ker}f=\{0\}$ and for every $x\in M$ we have
$$x=\underbrace{x_0\frac{f(x)}a}_{\in N}+\underbrace{\left(x-x_0\frac{f(x)}a\right)}_{\in\operatorname{Ker}f}$$
thus proving $M=N+\operatorname{Ker}f$ and hence $M=N\oplus\operatorname{Ker}f$ as internal direct sum.
Alternatively,
\begin{align}
N\times\operatorname{Ker}f&\to M&
(x,y)&\mapsto x+y\\
M&\to N\times\operatorname{Ker}f&
x&\mapsto\left(x_0\frac{f(x)}a,x-x_0\frac{f(x)}a\right)
\end{align}
are inverse each other isomorphisms.
A: If $\ker(f)=M$, then we can let $N=0$, and we're done.

So assume $\ker(f)\ne M$.

Then $f(M)\ne 0$, hence $f(M)=(y)$, for some nonzero $y\in R$.

Let $x\in M$ be such that $f(x)=y$, and let $N=\langle{x}\rangle$.

Claim:$\;M=N\oplus \ker(f)$.

Proof:

First we show $N\cap \ker(f)=0$.

Let $z\in N\cap \ker(f)$.

Since $z\in N$, we have $z=rx$ for some $r\in R$.
\begin{align*}
\text{Then}\;\;&z\in N\cap \ker(f)\\[4pt]
\implies\;&z\in \ker(f)\\[4pt]
\implies\;&f(z)=0\\[4pt]
\implies\;&f(rx)=0\\[4pt]
\implies\;&rf(x)=0\\[4pt]
\implies\;&ry=0\\[4pt]
\implies\;&r=0\;\;\;\text{[since $y\ne 0$]}\\[4pt]
\implies\;&rx=0\\[4pt]
\implies\;&z=0\\[4pt]
\end{align*}
hence $N\cap \ker(f)=0$.

It remains to show $N+\ker(f)=M$.

Let $m\in M$. Then we have
\begin{align*}
&f(m)\in f(M)\\[4pt]
\implies\;&f(m)\in (y)\\[4pt]
\implies\;&f(m)=ry\;\text{for some}\;r\in R\\[4pt]
\end{align*}
Let $n=rx$ and let $z=m-n$. Then we have $n\in N$, and 
\begin{align*}
f(z)&=f(m-n)\\[4pt]
&=f(m)-f(n)\\[4pt]
&=ry-f(rx)\\[4pt]
&=ry-rf(x)\\[4pt]
&=ry-ry\\[4pt]
&=0\\[4pt]
\end{align*}
hence $z\in\ker(f)$, so $m=n+(m-n)=n+z\in N+\ker(f)$.

Thus we have $M=N+\ker(f)$, which completes the proof.
