Sample variance derivation I have quite a simple question but I can't for the life of me figure it out.
For a set of iid samples $\,\,X_1, X_2, \ldots, X_n\,\,$ from distribution with mean $\,\mu$.
If you are given the sample variance as
$$ S^2 = \frac{1}{n-1}\sum\limits_{i=1}^n \left(X_i - \bar{X}\right)^2 $$
How can you write the following?
$$ S^2 = \frac{1}{n-1}\left[\sum\limits_{i=1}^n \left(X_i - \mu\right)^2 - n\left(\mu - \bar{X}\right)^2\right] $$
All texts that cover this just skip the details but I can't work it out myself. I get stuck after expanding like so
$$ S^2 = \frac{1}{n-1}\sum\limits_{i=1}^n \left(X_i^2 -2X_i\bar{X} + \bar{X}^2\right) $$
What am I missing?
Edit:
A similarly equivalent expression is often given that I also can't derive but which may be more obvious is
$$  S^2 = \frac{1}{n-1}\left[\sum\limits_{i=1}^n X_i^2 - n\bar{X}^2\right] $$
 A: $$\begin{align*}
\frac{1}{n-1}\left[\sum\limits_{i=1}^{n}\left(X_i - \mu\right)^2 - 
n\left(\mu - \bar{X}\right)^2\right]
&= \frac{1}{n-1}\sum\limits_{i=1}^{n}\left[\left(X_i - \mu\right)^2 - 
\left(\mu - \bar{X}\right)^2\right]\\
&= \frac{1}{n-1}\sum\limits_{i=1}^{n}\left(X_i - \bar{X}\right)
\left(X_i + \bar{X} - 2\mu\right).\end{align*}$$
Now, 
$$\sum_{i=1}^n (X_i - \bar{X}) = \sum_{i=1}^n X_i - \sum_{i=1}^n \bar{X}
= n\bar{X} - n\bar{X}= 0 $$
and so
$$\begin{align*}
\frac{1}{n-1}\sum\limits_{i=1}^{n}\left(X_i - \bar{X}\right)
\left(X_i + \bar{X} - 2\mu\right) 
&= \frac{1}{n-1}\left[\sum\limits_{i=1}^{n}\left(X_i - \bar{X}\right)X_i 
+ \sum\limits_{i=1}^{n}\left(X_i - \bar{X}\right)\left(\bar{X} - 2\mu\right)\right]\\
&= \frac{1}{n-1}\left[\sum\limits_{i=1}^{n}\left(X_i - \bar{X}\right)X_i 
+ \left(\bar{X} - 2\mu\right)\sum\limits_{i=1}^{n}\left(X_i - \bar{X}\right)
\right]\\
&=  \frac{1}{n-1}\left[\sum\limits_{i=1}^{n}\left(X_i - \bar{X}\right)X_i\right]\\
&= \frac{1}{n-1}\left[\sum\limits_{i=1}^{n}\left(X_i - \bar{X}\right)X_i
- \bar{X}\sum\limits_{i=1}^{n}\left(X_i - \bar{X}\right)\right]\\
&=  \frac{1}{n-1}\sum\limits_{i=1}^{n}\left(X_i - \bar{X}\right)^2\\
&= S^2 
\end{align*}$$
A: $$S^2=\frac{1}{n-1}\sum_{i=1}^n(X_i-\bar X)^2$$
$$=\frac{1}{n-1}\sum_{i=1}^n(X_i-\mu +\mu-\bar X)^2$$
$$=\frac{1}{n-1}\sum_{i=1}^n[(X_i-\mu)^2 +2(X_i-\mu)(\mu-\bar X)+(\mu-\bar X)^2]$$
$$=\frac{1}{n-1}[\sum_{i=1}^n(X_i-\mu)^2 +2\sum_{i=1}^n(X_i-\mu)(\mu-\bar X)+\sum_{i=1}^n(\mu-\bar X)^2]$$
$$=\frac{1}{n-1}[\sum_{i=1}^n(X_i-\mu)^2 +2n\sum_{i=1}^n(\frac{X_i}{n}-\frac{\mu}{n})(\mu-\bar X)+\sum_{i=1}^n(\mu-\bar X)^2]$$
$$=\frac{1}{n-1}[\sum_{i=1}^n(X_i-\mu)^2 -2n(\mu-\bar X)(\mu-\bar X)+n(\mu-\bar X)^2]$$
Let me add that replace $\frac{\sum_{i=1}^n X_i}{n}$  by  $\bar X$ in the last but one line. and flip it around to get the negative sign.
