Likelihood ratio test proof I'm trying to understand a proof given by my statistics textbook. It's a proof presented in relation to the likelihood ratio test.
$$\sum_{i=1}^n (x_i- \mu_0)^2 = \sum^n_{i=1}(x_i-\bar x)^2+n(\bar x-\mu_0)^2$$
I understand all the steps given, until they jump from
$$\sum(x_i-\bar x)^2 - 2(x_i-\bar x)(\bar x-\mu_0)+(\bar x-\mu^2_0)^2$$
to 
$$n(\bar x-\mu_0)^2+\sum^n_{i=1}(x_i-\bar x)^2$$
I don't really understand what's happened here. We were told that the middle term goes to zero, but then we're left with $\mu^2_0$ instead of $\mu_0$, and where does the $n$ come from? The summation operator? Some guidance would be really appreciated.

\begin{align}
& \sum_i \Big( (x_i-\bar x)^2 - 2(x_i-\bar x)(\bar x-\mu_0)+(\bar x-\mu_0)^2 \Big) \\
= {} & \left( \sum_i (x_i-\bar x)^2 \right) - 2 \sum_i \Big( (x_i-\bar x)\overbrace{(\bar x - \mu_0)} \Big)  + \sum_i \overbrace{(\bar x - \mu_0)^2}.
\end{align}
Observe that the two expressions under the $\overbrace{\text{overbraces}}$ do not change as $i$ runs from $1$ to $n$.  Therefore they can be pulled out:
$$
\left( \sum_i (x_i-\bar x)^2 \right) - \left( 2(\bar x - \mu_0) \sum_i (x_i-\bar x) \right) + \left( (\bar x - \mu_0)^2 \sum_i 1 \right)
$$
The third term above is $(\bar x - \mu_0)^2 n$.
The sum in the second term above is $0$: $$\sum_{i=1}^n (x_i - \bar x) = 0.$$ (Think about why that is so.)
