Where did I go wrong in my evaluation of the integral of cosine squared? $$\int{\cos^2(x)}dx$$
Where did I go wrong in my evaluation of this integral?
$$=x\cos^2x - \int-2x\sin(x)\cos(x)\,dx$$
$$=x\cos^2x + \int x\sin(2x)\,dx$$
$$=x\cos^2x + \left(\frac {-x\cos(2x)}2 -\int \frac{-\cos(2x)}2\,dx\right)$$
$$=x\cos^2x + \left(\frac {-x\cos(2x)}2 + \frac 12\cdot\frac{\sin(2x)}2\right)$$
$$x\cos^2x-\frac{x\cos(2x)}2+\frac{\sin(2x)}4 + C$$
And this is clearly wrong, but I don't know where I messed up in my calculations. Would anyone mind correcting me somewhere?

Notice, 
$$\int \cos^2 x dx=\int \cos x \cos x dx$$
$$=\int \cos x\sqrt{1-\sin ^2 x}dx$$
Let $\sin x=t\implies \cos x dx=dt$
$$\int \sqrt {1-t^2}dt$$
$$=\frac{1}{2}\left[t\sqrt {1-t^2}+\sin^{-1}(t)\right]$$ 
$$=\frac{1}{2}\left[\sin x\sqrt {1-sin^2x}+\sin^{-1}(\sin x)\right]$$ 
$$=\frac{1}{2}\left[\sin x\cos x+x\right]+C$$ 
$$=\frac{1}{2}\sin x\cos x+\frac{x}{2}+C$$ 
$$=\frac{x}{2}+\frac{1}{4}\sin2x+C$$ 
