Function Surjectivity Proof I have this question:

Prove that a function $f:X\rightarrow Y$ is surjective iff for any
  finite set $Z$ and any function $g:Z\rightarrow Y$ there exists a
  function $h:Z\rightarrow X$ such that $g$ is their composition: $f
 \circ h = g$. Assume $X,Y$ are also finite.

Can someone please show me how to complete this proof? I'm struggling with proving the forward direction, and think my work on the backwards direction (below) may not be rigorous enough.
If $f:X \rightarrow Y$ is surjective, then for any $g:Z \rightarrow Y$ there exists $h:Z \rightarrow X$ s.t. $f \circ h = g$. We can show that this holds: we know there is some $y' \in Y$ s.t. $g(z') = y'$, where $z' \in Z$. We also know that for the same $z'$, there is some $x' \in X$ s.t. $h(z') = x'$, as we may define $h$ as such. So we can define $f:X\rightarrow Y$ as mapping each $x'$ to $y'$, i.e. $f(x')=y'$,so $\forall y \in Y, \exists z \in Z s.t. f(h(z)) = y$. 

It turns out that there is no need for $X,Y$ to be finite.
For the forward direction, suppose that $f:X\to Y$ is surjective, that $Z$ is finite, and that $g:Z\to Y.$ We must define $h:Z\to X$ such that $f\circ h=g$. In particular, then, we need $f(h(z))=g(z)$ for each $z\in Z.$ Since $g:Z\to Y$ and since $f:X\to Y$ is surjective, then for each $z\in Z$ there is some $x\in X$ such that $f(x)=g(z).$ That is, the set $R_z:=\{x\in X:f(x)=g(z)\}$ is non-empty for all $z\in Z$. Since $Z$ is finite, then we may choose $x_z\in R_z$ for all $z\in Z,$ and define $h(z)=x_z,$ which will readily have the desired property, as you can (and should) prove.
Hint for the backward direction: Assume that for any finite set $Z$ and any function $g:Z\to Y$ there is a function $h:Z\to X$ such that $f\circ h=g.$ In particular, let $Z$ be some one-element set. The hypothesis should allow you to conclude directly that every element of $Y$ is in the range of $f$.
