If $A$ is a deformation retract of $X$ and $B$ is a deformation retract of $A$ then $ B$ is a deforemation retract of X If $A$ is a deformation retract of $X$ and $B$ is a deformation retract of $A$ then $ B$ is a deformation retract of $X$.
I am a beginner in Algebraic Topology so I tried to write every proof out  myself before consulting. I know there are various ways of handling this but I just want to confirm if what I wrote below makes sense.
$A\subset X$ is a deformation retract of X, let $r:X \to A$ such that $r$ is homotopic to the identity map on $X$. 
Define $H:X\times I \to X$ such that
$$H(x,0)=x$$
$$H(x,1)\in A$$
$$H(a,t)=a, a\in A$$ 
Thus $H(x,0)=x$ and $H(x,1)=r(x)$
Similarly, We have $B\subset A$, a deformation retract of A, Let $s:A \to B$ such that $s$ is homotopic to the identity map on $A$.
Define $F:A\times I \to A $ such that 
$$F(x,0)=x$$
$$F(x,1)\in B$$
$$F(b,t)=B, b\in B$$ 
Thus $F(x,0)=x$ and $F(x,1)=s(x)$
Now to show that $B$ is a deformation retract of $X$, I define
$q=s\circ r :X \to B$.
so $q$ is continuous being the composition of two continuous functions.
Claim: $G:X \times I \to X$. define by 
$$G(x,t)=F(H(x,t),t)$$ Is the required homotopy between $q$ and the identity on $X$.
$$G(x,0)=F(H(X,0),0)=F(x,0)=x$$
$$G(x,1)=F(H(x,1),1)=F(r(x),1)=s(r(x))=s\circ r$$
Is this a good way to go?
Any help will be appreciated. thank you.
 A: Your proof isn't quite correct, as there is a subtle domain error: in checking that $$G(x,0) = F(H(x,0),0) = F(x,0) = x,$$ you (implicitly) assume that $F(x,0) = x$ for all $x$ in $X$. However, $F$ is defined on $A \times I$, while $x$ can be anywhere in $X \supset A$.
Instead, you can define a deformation retract $G: X \times I \rightarrow X$ as follows:
\begin{align*}
G(x,t) = &H(x,2t), \quad & 0 \leq t \leq \frac{1}{2} \\
G(x,t) = &F(H(x,1),2t-1), \quad & \frac{1}{2} \leq t \leq 1.
\end{align*}
We will check that $G$ properly satisfies the conditions for a deformation retract. First, we have that $G(x,0)$ is the identity on $x$,
$$
G(x,0) = H(x,0) = x \;\text{for all}\;x \in X,
$$
and that the image of $G(x,1)$ is in $B$,
$$
G(x,1) = F(H(x,1),1) = F(a,1) \in B \;\text{for all}\;x \in X, \;\text{some}\; a \in A.
$$
Moreover,
\begin{align*}
G(b,t) = &H(b,2t) = b, \quad & 0 \leq t \leq \frac{1}{2} \\
G(b,t) = &F(H(b,1),2t-1) = F(b,2t-1) = b, \quad & \frac{1}{2} \leq t \leq 1
\end{align*}
shows that $G(b,t) = b$ for all $b \in B$ and hence $G(x,t)$ is the identity on $B$. All that remains is continuity; in particular, the only potential discontinuity would be at $t = \frac{1}{2}$. Computing
$$
F(H(x,1),2\Big{(}\frac{1}{2}\Big{)} - 1) = H(x,1)
$$
shows that the piecewise components of $G$ agree at $t = \frac{1}{2}$ and hence $G$ is continuous.
