Bijection between homotopy classes 
Let $X$ be a CW-complex and $w: Z \to Y$ a weak homotopy equivalence. Show that $$w_*: [X, Z] \to [X, Y]: [f] \mapsto [w \circ f]$$ is a bijection. Hint: use mapping cylinders.

I am having trouble with this question for both the injectiveness and surjectiveness.
Injective
Suppose $[w \circ f] = [w \circ g]$. We can factor $f$ as $X \xrightarrow{i_X} M(f) \xrightarrow{p} Y$ where $i_X$ is a closed inclusion and $p$ is a homotopy equivalence (and $M(f)$ is the mapping cylinder of $f$) and similarly factor $g$ as $X \xrightarrow{j_X} M(g) \xrightarrow{q} Y$. 
I want to use Whitehead on $w$. The space $Z$ is not a CW-complex, but it is homotopy equivalent to $M(f)$ and $M(g)$, which are. Similarly $Y$ is homotopy equivalent to $M(w \circ f)$ and $M(w \circ g)$. Composing $w$ with the homotopy equivalences gives a map $M(f) \to M(w \circ g)$ (we can swap $f$ and $g$ around), and since homotopy equivalences do not change the $\pi_n$, this is a weak homotopy equivalence, hence by Whitehead a homotopy equivalence. I don't know what to do with this.
Surjective
Given a map $f: X \to Y$, I can't figure out a way to factor it via $z$ as $w$ has no (partial) inverse.  
 A: Use the factorisation $Z \overset{j_Z}{\to} M(w) \overset{p}{\to} Y$ of $w$ to show that $j_Z$ is a weak homotopy equivalence. This implies that $(M(w), j_Z(Z))$ is $n$-connected for every $n$.


*

*For surjectivity, any $f : X \to Y$ gives $j_Y \circ f : (X, \varnothing) \to (M(w), j_Z(Z))$. By the above, and that $X$ is a CW-complex, this composition will be homotopic to $j_Z \circ \tilde{f}$ for some $\tilde{f} : X \to Z$. It is now easy to see that $[f] = [w \circ \tilde{f}] = w_* [\tilde{f}]$.

*For injectivity, if $f, g : X \to Z$ are such that $[w \circ f] = [w \circ g]$, let $H : X \times [0, 1] \to Y$ be a homotopy between them. We can slightly alter this to obtain
$$ H': X \times [0, 1] \to M(w) : (x, t) \mapsto \left\{ \begin{array}{cl} (f(x), 3t) & \text{if } 0 \leq t \leq 1/3 \\ H(x, 3t - 1) & \text{if } 1/3 \leq t \leq 1/3 \\ (g(x), 2 - 3t) & \text{if } 2/3 \leq t \leq 1/3 \\  \end{array} \right.$$
and view $H'$ as a map of pairs $H' : (X \times [0, 1], X \times \{ 0, 1 \}) \to (M(w), j_Z(Z))$. Similar as to before, $H'$ will be homotopic (relative to $X \times \{ 0, 1 \}$) to some $\tilde{H} : X \times [0, 1] \to M(w)$ with image in $j_Z(Z)$. Now it is easy to see this gives a homotopy between $f$ and $g$.
