# Better proof that vector fields on submanifolds extend globally iff submanifold is closed

I just finished my own proof of one of the problems in Lee's Smooth Manfolds, 2nd ed., but I wonder if anyone knows a better (less messy) solution. It's problem 8-15, the "Extension Lemma for Vector Fields on Submanifolds." Here's the part of the exercise which I had some trouble with:

Let $S$ be an embedded submanifold with or without boundary of a manifold $M$. Every vector field $X \in \mathfrak{X}(S)$ extends to all of $M$ if and only if $S$ is properly embedded.

I proved that if $S$ is properly embedded, then all vector fields extend globally easily. It's the reverse direction I had trouble with. My idea was that if $S$ is not closed in $M$, then take some point $p \in \overline{S} \setminus S$. I showed that one can find a smooth path $\gamma: (-\epsilon, \epsilon) \to M$ such that $\gamma$ is an embedding, $\gamma(0) = p$, $\gamma(-\epsilon, 0) \subset S$, and in some coordinate neighborhood of $p$, $|\gamma'(t)| = 1$. Then I defined the function $f: \gamma(-\epsilon, 0) \to \mathbb{R}$ as $f(x) = -1/\gamma^{-1}(x)$ (the idea is that this is a smooth function which blows up as $x \to p$). Finally I defined the vector field $f(x) \gamma'(\gamma^{-1}(x))$ on $\gamma[-\epsilon/2, 0)$. This is a smooth vector field on a closed subset of $S$, hence by the extension lemma proved earlier in the text, it extends to a smooth vector field on $S$. Clearly it does not extend to a smooth vector field on all of $M$ though, because in the local coordinate chart near $p$, its norm blows up.

The above argument feels very messy to me. I don't like the process I went through to find a smooth function on $S$ which blows up near $p$; surely there's a simpler way to do this?