System of derivative equations best way to solve $$ 
f_x = 2x\sin(z)\\
f_y = 3y^2\sin(z)\\
f_z = (x^2+y^3)\cos(z)\\
$$
Where the indexes represent the partial derivative with respect to the letter.
What we did in the solutions was the following:
We integrated $f_x$ and got $f = x^2 \sin(z)+g(y,z)$
Then we also integrated $f_y$ and got $g = y^3\sin(z)+h(z)$
Why is it in the second case that there is only $h(z)$ and not $h(y,z)$ as it is in the first case.
And then for $f_z$ we did: $(x^2+y^3)\cos(z) \implies x^2\cos(z)+g_z = (x^2+y^3)\cos(z) \implies g_z = y^3\cos(z)$
And then we somehow got: $f(x,y,z) = (x^2+y^2)\sin(z)+c $
However I do not understand this procedure. Can somebody explain or if there is a better procedure.

$$f_x = 2x\sin(z)$$
Integration gives:
$$f = x^2 \sin(z)+g(y,z)$$
Differentiate with respect to the variable $y$:
$$f_y = \dfrac {dg(y,z)}{dy}$$
Now use $f_y = 3y^2\sin(z)$:
$$ 3y^2\sin(z)=\dfrac {dg(y,z)}{dy}$$
Adter integration:
$$ y^3\sin(z)+h(z)=g(y,z)$$
Since $g=g(y,z)$ the variable $x$ is not involved.
In the first case you have that:
$$f_x = 2x\sin(z)\\$$
$f=f(x,y,z)$ that's why you have the $g(y,z)$ after integration:
$$f(x,y,z) = x^2\sin(z)+g(y,z)$$
