GP 1.4.4 An extension of partial converse of preimage theorem. This is exercise 1.4.4 on Guillemin and Pollack's Differential Topology

Suppose that $Z \subset X \subset Y$ are manifolds, and $z \in Z$. Then there exist independent functions $g_1, \dots, g_l$, on a neighborhood $W$ of $z$ in $Y$ such that
  $$Z \cap W = \{y \in W : g_1(y) = 0, \dots, g_l(y) = 0\},$$
  $$X \cap W = \{y \in W : g_i(y) = 0, \dots , g_m(y) = 0\},$$
  where $l-m$ is the codimension of $Z$ in $X$.

I tried to set up the proof as following:
Suppose that $Z \subset X \subset Y$ are manifolds, and $z \in Z$. 
Let $Z$ and $X$ have codimensions $l$ and $m$ in $Y$, $Z$ has codimension $l-m$ in $X$.
From the partial converse to the preimage theorem, there exist independent functions $f_1, \dots f_m$ on a neighborhood $U$ of $z$ in $Y$ such that $X \cap U$ is the common vanishing set of the $f_i$.
We also know that there exist independent functions $h_{m+1}, \dots, h_l$ on a neighborhood $V$ of $z$ in $X$ such that $Z \cap V$ is the common vanishing set of the $h_i$.
And then I don't know why $h_i$s are smooth, and how should I continue.
Any ideas? Thank you.
 A: tl;dr: straighten the neighborhood in $Y$ so that $Z$ looks flat, straighten the neighborhood in $Z$ so that $X$ looks flat, and extend the latter straightening some way into $Y$.
I don't know the theorem names off the top of my head, but here's how I'd approach this:
WLOG $z=0$ and $Y = \mathbb{R}^n$ for some $n$.  Since $Z$ is a smooth submanifold of codimension $l$, there is some smooth $f\times g\colon U\cong V\times W$ where $U\subseteq\mathbb{R}^n$, $V\subseteq\mathbb{R}^l$, $W\subseteq\mathbb{R}^{n-l}$, and for $x\in U$, $x\in Z$ iff $f(x)=0$. (I want to say this is the domain-straightening theorem?)  The neighborhood of $x$ in $Z$ looks like $W$, so we'll identify the two for convenience.
Now $X$ is a smooth submanifold of $Z$ (codimension $l$), so by the same theorem, after possibly shrinking $W$ (and $U$ to match), there is some smooth $h\times k\colon W\cong S\times T$ where $S\subseteq\mathbb{R}^{l-m}$, $T\subseteq\mathbb{R}^{n-m}$, and for $x\in W$, $x\in X$ iff $h(x)=0$.
Of the $g_i$, the first $l$ are the components of $f$, and the remaining $m-l$ are the components of $h\circ g$.  Apologies for the notational weirdness.
