Let functions $ f: A \to B$ and $g: B \to A$, suppose that $ g \circ f = i_A$. Prove that if $f$ is onto, then $g$ is one-to-one 
For nonempty sets $A$ and $B$ and functions $ f: A \to B$ and $g: B \to A$, suppose that $ g \circ f = i_A$. Prove that if $f$ is onto, then $g$ is $1-1$.

Here is what I started, I don't think it's correct. 
Suppose $f$ is onto 
i.e for each element $b \in B$ there is an element of $a\in A$, $f(a)=b$. (definition of onto). 
Let $y,\ z$ be any two elements of $B$.Then $y=f(a)$ and $z=f(b)$ for some $a,b \in A$. 
If $g(y)=g(z)$, then $g(f(a)) = g(f(b))$,which implies that $a=b$, so $f(a)=f(b)$, so $y=z$. 
Thus, whenever $g$ maps $y$ and $z$ to the same element in $A$, $y=z$, so $g$ is one-to-one. 
PS: New to proof writing, any constructive criticism is much appreciated. 
 A: Your proof is correct, as someone else stated.  I just wanted to post my version of the proof with all of the details laid out, because I personally think no details should be left out of a proof (otherwise, it is usually hard for me to follow it).  Here is my version:
Let $f: A \rightarrow B$ and $g: B \rightarrow A$ be functions such that $g \circ f = i_{A}$.  Suppose that $f$ is onto.  Then we want to show that $g$ is one-to-one, that is, if $g(a) = g(b)$, then $a = b$.
Suppose $a, a' \in A$ such that $g(a) = g(a')$.  We want to show $a = a'$.  But since $a,a' \in A$ and $f$ is onto, then we know there exists $b, b' \in B$ such that $f(b) = a$ and $f(b') = a'$.  Thus, $g(a) = g(a') \implies g(f(b)) = g(f(b'))$.  But by assumption, $g \circ f$ is the identity map, so we have $g(f(b)) = b$, and $g(f(b')) = b'$.   But this shows that $b = b'$ since $g(f(b)) = g(f(b'))$.  Finally, since $f$ is by assumption a function, it is well-defined, so one input results in at most one output.  Thus, since $b = b'$, they are the same input, which means $f(b) = f(b')$, and this implies $a = a'$, as desired.
