I am studying ring theory and I am having a hard time understanding a part of a proof of a certain theorem. Note that in my lecture notes, a ring is by definition commutative with $1$. Let $R$ be a ring, then the set of units of $R$ is denoted by $R^*$.
Consider the following theorem:
Let $R$ be a principal ideal domain (PID) and $\pi\in R$ irreducible. For any $a,b\in R$ with $\pi|ab$ we have $\pi|a$ or $\pi|b$.
The following is the first part of the proof from my lecture notes:
Consider the ideal $(a,\pi)$. Since $R$ is a PID this ideal is generated by a single element, which we call g. Note that $g|\pi$. Hence either $g$ is a unit, or $g=\epsilon\pi$ with $\epsilon\in R^*$. In the second case, since $g|a$ we also get $\pi|a$ and our assertion is proven.
The second part of the proof covers the case in which $g$ is a unit; I understand what's going on there (under the assumption that $g$ is indeed a unit) so I've omitted it. Please note that this is the proof word by word, i.e. I have quoted it from my lecture notes.
First of all, is it true that, since $(g)=(a,\pi)$ we have $\{rg\ |\ r\in R\}=\{r_1a+r_2\pi\ |\ r_1,r_2\in R\}$ and by choosing $r_1=0$ and $r_2=1$ we have $rg=\pi$ for some $r\in R$, thus $g|\pi$? If this is true, then by similar reasoning one can proof that $g|a$ (which is stated in the last sentence of the proof).
Next, the proof says that $g$ is either a unit or $g=\epsilon\pi$ for some unit $\epsilon$. By definition, we see from the factorisation above that either $g$ or $r$ is a unit. The first case corresponds to the statement in the proof that $g$ can be a unit. But if $g$ is not a unit, why is $g=\pi\epsilon$ for some unit $\epsilon$?
Lastly, how does $\pi|a$ follow from all that has been said in the proof?
EDIT:
As requested by a user in the comments, here is the second part of the proof in my lecture notes, along with the first one for easy reading:
Consider the ideal $(a,\pi)$. Since $R$ is a PID this ideal is generated by a single element, which we call g. Note that $g|\pi$. Hence either $g$ is a unit, or $g=\epsilon\pi$ with $\epsilon\in R^*$. In the second case, since $g|a$ we also get $\pi|a$ and our assertion is proven.
Now suppose that $g$ is a unit and hence $(a,\pi)=R$. In this case there exist $x,y\in R$ such that $ax+\pi y=1$. Multiply by $b$ to get $abx+\pi by=b$. Both terms on the left are divisible by $\pi$. Hence the sum $b$ is also divisible by $\pi$ which proves our theorem.