Local extension of smooth funtion to a embedded manifold I'm trying to proof the following problem from Lee's Book:

Suppose $M$ is a smooth manifold and $S\subseteq M$ is a smooth submanifold.
Show that $S$ is embedded if and only if every $f\in C^\infty(S)$ has a smooth extension to a neighborhood of $S$ in M.

I've shown that $S$ embedded $\Longrightarrow$ Every $f\in C^\infty(S)$ has a smooth extension to a neighborhood of $S$ in M.
But the converse it's being hard to see. The book gives us a hint, but I have no ideia how this can be helpful. The hint is:

If $S$ is not embedded, let $p\in S$ be a point that is not in the domain of any slice chart. Let $U$ be a neighborhood of $p$ in $S$ that is embedded, and consider a function $f\in C^\infty(S)$ that is supported in $U$ and equal to $1$ at $p$.

Maybe a contradiction argument be necessary, but I can't realise this.
How can I prove this? Any kind of help will be useful.
 A: In the situation described, we have an injective immersion $h:T\to M$ from a smooth manifold $T$, with $S=h(T)$. Suppose $h$ is not en embedding, which means it is not open when $S\subset M$ is equiped with the subspace topology. Hence there exists some point $q\in T$ with a neighborhood $V$ in $T$ such that $h(V)$ is not a neighborhood of $p=h(q)$ in $S$ as subspace of $M$. Now pick a smooth function $g:T\to\mathbb R$ supported in $V$ with $g(q)=1$. The $f$ in the hint should be $f=g\circ h^{-1}$, which is surely smooth in $S$ as immersed manifold. Let $F:M\to\mathbb R$ be a smooth extension of $f$. Then $F$ is continuous, and the set $\{F>0\}$ is open in $M$. Thus $W=\{F>0\}\cap S$ is an open set of $S$ as subspace of $M$ and 
1) $p\in W$, because $F(p)=g\circ h^{-1}(p)=g(q)=1$, and
2) $W\subset h(V)$, because if $x\notin h(V)$ then $y=h^{-1}(x)\notin V$ and $0=g(y)=f(x)=F(x)$.
We conclude that $h(V)$ is a ndhd of $p$ in the subspace topology of $S$ against the initial assumption.
A: Let $dim\ S=k$ and $dim\ M = m$. Assume by contradiction that $S$ is not embedded. Then there exists $p\in S$ such that it is not in the domain of any slice chart, meaning that for each $(U,\phi)$ chart for $M$, $\phi(U) \not\subset \mathbb{R}^k\times \{0\}^{m-k}$. Now consider an  embedded neighborhood $V$ of $p$ along with a local chart (in S) $(V,\psi)$. Apply one direction of the lemma to $f\in C^\infty(S), supp(f)\subset V,f(p)=1$ and obtain
$$
f\in C^\infty(\tilde{S}),\quad \tilde{S}\subset M \text{ open neighborhood of } S.
$$
$\tilde{S}$ is an open submanifold, therefore it inherits the topology and local charts (their restriction) which endow $M$. Let $(U,\phi)$ be a local chart for $p$ (in M).
Since $\psi:V\to\psi(V)$ is a diffeomorphism, we can change the first entries of $\phi$ and fit them in a form
$$
\phi = (\phi_1,\ldots,\phi_n) \ \forall\ p\in U \quad \phi = (\psi,0,\ldots,0) \ \forall\ p\in V .
$$
The vector $(\phi_{k+1},\ldots,\phi_m)$ cannot be identically zero on $U\cap S\setminus V$ otherwise we would have a $k$-slice for $S$.
\ Consider a countable base of open sets for $p$ in $M$, namely $\{U_n\}$. For each open neighborhood choose a $x_n \in U_n\cap S \setminus V$. The sequence $\{x_n\}$ is such that
$$
\{x_n\} \subset U\cap S\setminus V \ \Rightarrow  x_n \not\in supp(f)\subset V
$$
which contradicts continuity (and so smoothness) of $f$ since
$$
x_n \to p, \quad f(x_n) = 0 \not\to 1 = f(p)
$$
