Proof verification: If $f$ is surjective and $gf$ is injective prove that $g$ is injective. I have written a proof, and I would appreciate verification. The problem is picked from "Set Theory and Matrices" by I. Kaplansky.

Proof. Let $a_1=f(x)$ and $a_2=f(y)$, then
$g(a_1)=g(a_2) \Longrightarrow g(f(x))=g(f(y)) \overset{def}{\Longrightarrow} x=y \Longrightarrow f(x)=f(y) \Longrightarrow a_1=a_2$
Therefore, according to transitivity, we get that $\,g(a_1)=g(a_2) \Longrightarrow a_1=a_2$, which is (one of) the definition(s) of an injective function. Thus, $g$ is injective if $gf$ is injective. QED

My insecurity is foremost the first step as well as some unclarity about explicitly highlight that $f$ is surjective. 
 A: First be precise about what you are proving: Let $f\colon X\to Y$ be a surjective map  and $g\colon Y\to Z$ be a map such that $g\circ f$ is injective. Then $g$ is injective.
In your proof you never explicitly state where you are using  the fact that $f$ is surjective. I would rewrite the first step as follows. Suppose that $g(a_1)=g(a_2)$ for some $a_1, a_2\in Y$. Since $f$ is surjective there exists $x, y\in X$ such that $f(x)=a_1$ and $f(y)=a_2$.
Then we can proceed with your proof. I would also recommend using words rather than symbols when writing proofs. 
So to continue with the proof I would write, it follows that $g(f(x))=g(f(y))$. Since $g\circ f$ is injective it is the case that $x=y$ and hence $a_1=a_2$.
A: Let $a_1,a_2\in\mathrm{dom}(g)$. Since $f$ is surjective for each pair $a_1,a_2\mathrm{dom}(g)$ there exists $x,y\in\mathrm{dom}(f)$ such that $a_1=f(x)$ and $a_2=f(y)$. In this case we want to see that $g$ is injective whenever $gf$ is injective. For that let's suppose that $g(a_1)=g(a_2)$ we have $g(f(x))=g(a_1)=g(a_2)=g(f(y))$. Since $gf$ is injective we get
$$ g(f(x))=g(f(y)) \ {\Longrightarrow} \ x=y $$ 
this implies that $ f(x)=f(y) \Longrightarrow a_1=a_2$
Therefore, $\,g(a_1)=g(a_2) \Longrightarrow a_1=a_2$. Thus, $g$ is injective if $gf$ is injective.
