Finding bump function on a smooth manifold using partitions of unity. Let $M$ be a smooth manifold. Let $A$ and $B$ be disjoint closed sets of $M$. Show there exists a smooth function $f$ such that $f^{-1}(0)=A$ and $f^{-1}(1)=B$. 
This is my idea so far, 
Since $A$ and $B$ are disjoint closed subsets $\{M-A,M-B\}$ is an open cover for $M$. Therefore there exists a partition of unity $\{\psi_{1},\psi_{2}\}$ with $\psi_{1}$ supported in $M-A$ and $\psi_{2}$ supported in $M-B$. Furthermore $\psi_{1}+\psi_{2}=1$. Then $\psi_{1}(1-\psi_{2})$ is zero on $A$ and $1$ on $B$. I get the inclusions $A\subset f^{-1}(0)$ and $B\subset f^{-1}(1)$. I've tried adding a few more open sets to the cover like $M-(A\cup B)$ and $(M-A)-B$ and $(M-B)-A$ but I still can't ensure that the function only vanishes at $A$. 
Then I moved on to attempt to find any bump function that is 1 only on $A$ and ran into the same problem. 
Am I missing something here or do I just need to be clever with how I define a function. Any hints would be much appreciated. Thanks.  
 A: You can construct a proof using the following steps:


*

*First show that for for an open interval $(a,b)$ there exists a smooth function $\phi: \mathbb R\to [0,\infty)$ such that $\phi^{-1}(0,\infty)=(a,b)$, thus $\phi$ vanishes outside $(a,b)$. Then do the same for boxes $(a_1,b_1)\times\dots\times (a_n,b_n)$ of $\mathbb R^n$, i.e. find $\phi:\mathbb R^n\to [0,\infty)$ with $\phi^{-1}(0,\infty)=(a_1,b_1)\times\dots\times (a_n,b_n)$

*Show that the above is true when you replace $(a_1,b_1)\times\dots\times (a_n,b_n)$ by an open subset $U$ of $\mathbb R^n$. To do this, show that $U$ can be written as union of such open boxes, such that each $p\in U$ is contained in finitely many boxes. Then choose a $\phi$ as above for each box. The sum of those $\phi$'s, will be the desired function for $U$. 

*Then prove the same result for the manifold $M$. Use a partition of unity and the previous results for $\mathbb R^n$ to do this.

*Finally, if $A,B\subset M$ are disjoint and closed, then by the previous we can find $\phi_1 ,\phi_2 :M\to [0,\infty)$ such that $\phi^{-1}_1(0)=A$ and $\phi^{-1}_2(0)=B$. The sum $\phi_1+\phi_2$ never vanishes since $A\cap B=\emptyset$. Therefore, we can define $\phi:= \phi_2/(\phi_1+\phi_2)$. This is smooth on $M$, it attains values in $[0,1]$, and has the desired property that $\phi^{-1}(1)=B, \phi^{-1}(0)=A$

