Why are retracts of connected manifolds embedded submanifolds? I'm now working on this exercise:

Let $f: M \rightarrow M$ be a smooth map on a smooth, connected manifold $M$, satisfying $f \circ f = f$, then prove that $f(M)$ is an embedded manifold of $M$.

I have viewed many existed posts discussing this exercise, especially this one:Proving $f(X)$ is a submanifold. In this post, the question provides hints as follows:


*

*(1) $\mathrm{rk}_p f \leq \mathrm{rk}_{f(p)} f$ for all $p \in M$ ;

*(2) The rank of $f$ is constant along $f(M)$;

*(3) The rank of $f$ is constant in an open neighbourhood of $f(M)$;

*(4) Show that $f(M)$ is a submanifold when the above holds (using the constant rank theorem).


I'm managed to prove the first two points. (And I shall post a detailed answer on the above link later)
My question is: how to prove the third and the fourth point?
My attempts for (3): I have actually proved a stronger result than (2), namely the rank of $f$ on $f(M)$ is $\max_{p \in M} \mathrm{rk}_p f$. (See rank of function on connected manifold for this.) So I'm trying to show that for any $p \in f(M)$, there exists an open neighborhood $U_p$ in $M$, such that $\mathrm{rk}_q f \geq r$ for any $q \in U_p$. Also by (1), we see that $\mathrm{rk}_q f \leq \mathrm{rk}_{f(q)} f = r$. Combining these two together, $\mathrm{rk}_q f = r$ for any $q \in U_p$. Then taking the union of $U_p$ over $p \in f(M)$, we are done for (3). BUT, how to find such a desired $U_p$? I'm thinking of using the connectness of $f(M)$.  [P.S. This method is adapted from P. W. Michor, Topics in Differential Geometry, Section 1.15.]
My attempt for (4): I don't know how to apply the constant rank theorem here. My understanding of the constant rank theorem is:

Let $f: M^m \rightarrow N^n$ be a smooth map between smooth manifolds $M^m$ and $N^n$. For $q \in N^n$, if there exists an open neighborhood $U$ of $f^{-1}(q)$, such that $\mathrm{rank} f$ is a constant on $U$, then $f^{-1}(q)$ is an embedded submanifold of $M^m$ (if the fiber $f^{-1}(q)$ is not empty).

Here in my exercise, I think I should consider $f$ (in my exercise) as $f$ (in the above theorem), $M$ as $M^m$ and $M$ as $N^n$. Then how can I write $f(M)$ as a fiber of a point $q \in M$?
 A: For (3) maybe this will help
How to prove that the rank of a matrix is a lower semi-continuous function?
For (4) Try this version of the constant rank theorem http://www.math.toronto.edu/mgualt/MAT1300/week3.pdf.
A: For (3):
Assuming you allready know that the rank of $f$ is maximal on $f(M)$:

The rank
$$\text{rk}\, f:M\to\mathbb Z$$
is lower-semicontinous and hence locally only can  jump up.

This follows from the lower-semicontinuity of the rank of $n\times n$-matrices. So the set
$$\{x\in M:\text{rk}_xf=r\}=\{x\in M:\text{rk}_xf>r-\frac 12\}$$
is open and hence an open neighborhood of $f(M)$.
For (4):
Let $x_0\in f(M)$. Then by the constant rank Theorem there are charts $(U,\phi)$, $(V,\psi)$ about $x_0=f(x_0)$ with $f(U)\subseteq V$ and
$$\psi\circ f\circ \phi^{-1}(x_1,\dots,x_n)=(x_1,\dots,x_r,0,\dots,0)$$
and by shrinking $V$ one can assume $\psi(f(U))=\psi(V)\cap(\mathbb R^r\times\{0\}$).
Now set $W=U\cap V$, which is an open neighborhood of $x_0$. $f\circ f=f$ implies $W\cap f(M)=W\cap f(U)$ and $\psi$  injective implies $\psi(W\cap f(U))=\psi(W)\cap\psi(f(U))$, so
$$\psi(W\cap f(M))=
\psi(W\cap f(U))=
\psi(W)\cap \psi(V)\cap (\mathbb R^r\times\{0\}))=
\psi(W)\cap(\mathbb R^r\times\{0\})$$
which shows that $f(M)$ is a submanifold of $M$.
