Evaluate $\ \int_{|z|=2}\frac{z^2+1}{(z-3)(z^2-1)}\ dz$ 
I am trying to solve $$\ \int_{|z|=2}\frac{z^2+1}{(z-3)(z^2-1)}\ dz,$$
  using Cauchy's Integral Formula. 

My attempt:
$$I=\int_{|z|=2}\frac{z^2+1}{(z-3)(z^2-1)}\ dz=\int_{|z|=2}\frac{z^2+1}{(z-3)(z-1)(z+1)}\ dz$$
Now, $I$ has singularities $\pm 1, 3$, but only $\pm 1$ lie inside the circle $|z|=2$. Now if we draw the following

We see that 
$f(z)=\frac{z^2+1}{(z-3)(z-1)}$ and $g(z)=\frac{z^2+1}{(z-3)(z+1)}$ are holomorphic outside the green and blue ball respectively.
Now, i've been told that we can use a corollary of the Cauchy-Goursat theorem to show that $$I=\int_{a} \frac{f(z)}{z+1}\ dz+\int_{b} \frac{g(z)}{z-1}\ dz,$$ where $a$ and $b$ are the contours of the green and blue cirlces respectively. But I don't understand why this is? I can solve beyond this point.
 A: *

*Method 1: Using Partial fractions:
$$ \int_{|z|=2}\frac{z^2+1}{(z-3)(z^2-1)} dz = \int_{|z|=2}\frac{-\frac12}{z-1} + \frac{\frac14}{z+1} + \frac{\frac54}{z-3} dz$$
$$ = \int_{|z|=2}\frac{-\frac12}{z-1}dz + \int_{|z|=2}\frac{\frac14}{z+1}dz + \int_{|z|=2}\frac{\frac54}{z-3} dz$$
$$ = -\frac12 (2\pi i) + \frac14 (2\pi i) + \frac54 (0) = \frac{-\pi i}{2}$$


*Method 2: Boundaries of the balls, $\gamma_1$ and $\gamma_2$, respectively that you drew:

$$ \int_{|z|=2}\frac{z^2+1}{(z-3)(z^2-1)} dz$$
$$ = \int_{\gamma_1}\frac{z^2+1}{(z-3)(z^2-1)} dz + \int_{\gamma_2}\frac{z^2+1}{(z-3)(z^2-1)} dz + \int_{\text{the boundary of the region inside} \ |z|=2 \ \text{but outside} \ \gamma_1 \ \text{and} \ \gamma_2}\frac{z^2+1}{(z-3)(z^2-1)} dz$$
$$ = \int_{\gamma_1}\frac{z^2+1}{(z-3)(z^2-1)} dz + \int_{\gamma_2}\frac{z^2+1}{(z-3)(z^2-1)} dz + 0 \tag{1}$$
$$ = \int_{\gamma_1} \frac{\frac{z^2+1}{(z-3)(z-1)}}{(z+1)} dz + \int_{\gamma_2} \frac{\frac{z^2+1}{(z-3)(z+1)}}{(z-1)} dz$$
$$ = \frac{z^2+1}{(z-3)(z-1)}|_{z=-1} (2\pi i) + \frac{z^2+1}{(z-3)(z+1)}|_{z=1} (2\pi i)$$
$$ = \frac{2}{(-4)(-2)} (2\pi i) + \frac{2}{(-2)(2)} (2\pi i) = \frac{-\pi i}{2}$$


*Method 3: Using Residue:
$$ \int_{|z|=2}\frac{z^2+1}{(z-3)(z^2-1)} dz = (2\pi i) \text{Res}_{\{z=1\}}(\frac{z^2+1}{(z-3)(z^2-1)}) + (2\pi i) \text{Res}_{\{z=-1\}}(\frac{z^2+1}{(z-3)(z^2-1)})$$
$$ = (2\pi i) \lim_{z \to 1} (z-1)(\frac{z^2+1}{(z-3)(z^2-1)}) + (2\pi i) \lim_{z \to -1} (z+1)(\frac{z^2+1}{(z-3)(z^2-1)}) = \frac{-\pi i}{2}$$

$(1)$ is because "a corollary of the Cauchy-Goursat theorem" states that

$$0= \int_{\gamma} f(z) dz$$ if $f$ is holomorphic in the region bounded by $\gamma$ under suitable conditions of $\gamma$, where conditions on the region and $\gamma$ may vary by book.

