Compute $\int_{0}^{2\pi}\frac{1}{(2+\cos\theta)^2}\,d\theta$ I''m stuck in a exercise in complex analysis concerning integration of rational trigonometric functions. Here it goes: 
We want to evaluate $\int_{0}^{2\pi}\frac{1}{(2+\cos\theta)^2}\,d\theta$. 
Here's my work:
Let $z=e^{i\theta}$ so that $d\theta=dz/iz$ and $\cos \theta = \frac12 (z+z^{-1})$.  We have 
$$\begin{align}
I&=\int_{0}^{2\pi}\frac{1}{(2+\cos\theta)^2}\,d\theta \quad (1)\\\\ 
&=\oint_C \frac{1}{(2+\frac{z+z^{-1}}{2})^2}\frac{dz}{iz} \quad (2)\\\\ 
&=\frac1i\oint_C \frac{4}{(4+z+z^{-1})^2}\frac{dz}{z} \quad (3) \\\\ 
&=\frac4i\oint_C \frac{1}{(z^2+4z+1)^2}\,dz \quad (4) \\\\ 
&=\frac4i\oint_C \frac{1}{(z-(-2+\sqrt3)^2(z-(-2-\sqrt3)^2}\,dz \quad (5)\\\\
&=\frac4i\oint_Cf(z)\,dz \quad (6)
\end{align}$$
where $C$ is the unit circle in the complex $z$-plane. 
The function $f(z)$ has singularities at $(-2\pm\sqrt3)$ but only $(-2+\sqrt3)\in int(C)$. Therefore,
$$\oint_Cf(z)\,dz=2\pi i (Res(f, (-2+\sqrt3))) \quad (*)$$
Since $(-2+\sqrt3)$ is a pole of order $2$, after a quick calculation I get 
$$Res(f, (-2+\sqrt3)=-\frac{\sqrt3}{3}$$
and so for $(*)$ I get 
$$\oint_Cf(z)\,dz=2\pi i (-\frac{\sqrt3}{3})=-\frac{2\pi\sqrt3i}{3}.$$
Hence, by $(6)$, I find
$$\frac4i\oint_Cf(z)\,dz=\frac4i \left(\frac{-2\pi\sqrt3i}{3}\right)=-\frac{8\pi\sqrt3}{3}.$$

My solution however is not correct. The given integral evaluates to $\frac{4\pi}{3\sqrt3}$ (verified with Wolfram). I suspect there must be a flaw in one of my steps from $(1)$ to $(6)$ but I can't find it. 

Edit
$$I(a)=\int_{0}^{2\pi}\frac{1}{a+\cos x}dx=\int_{-\pi}^{\pi}\frac{1}{a-\cos x}dx=2\int_{0}^{\pi}\frac{1}{a-\cos x}dx$$
We know $\cos x=\large \frac{1-\tan^2\frac x 2}{{1-\tan^2\frac x 2}}$,thus
$$I(a)=2\int_{0}^{\pi}\frac{{1+\tan^2\frac x 2}}{(a-1)+(a+1)\tan^2\frac{x}{2}}dx=\frac{2}{(a+1)}\int_{0}^{\pi}\frac{1+\tan^2\frac x 2}{\frac{a-1}{a+1}+\tan^2\frac{x}{2}}dx$$
set $u=\tan\frac{x}{2}$, we have
$$I(a)=\frac{4}{a+1}\int_{0}^{+\infty}\frac{1}{\frac{a-1}{a+1}+u^2}du=\frac{4}{a+1}\sqrt{\frac{a+1}{a-1}}\tan^{-1}\left(\frac{a+1}{a-1}u\right)\large|_{0}^{\infty}=\frac{2\pi}{\sqrt{a^2-1}}$$

$$I(a)=\int_{0}^{2\pi}\frac{1}{a+\cos x}dx=\frac{2\pi}{\sqrt{a^2-1}}$$

$$I'(a)=-\int_{0}^{2\pi}\frac{1}{(a+\cos x)^2}dx=-\frac{2\pi a}{(a^2-1)^\frac32}$$
In the other words

$$\int_{0}^{2\pi}\frac{1}{(a+\cos x)^2}dx=\frac{2\pi
 a}{(a^2-1)^\frac32}$$

now set $a=2$
