Calculating variance for a sequence of i.i.d. variables which seems non-partitionable 
Let $(Z_n : 1 \leq n < \infty )$ be a sequence of independent and identically distributed (i.i.d.) random variables with $$\mathbb{P}(Z_n=0)=q=1-p,\quad \mathbb{P}(Z_n=1)=p.$$ Let $A_i$ be the event $$\{Z_i=0\}\cap\{Z_{i-1}=1\}.$$  If $U_n$ is the number of times $A_i$ occurs for $2 \leq i \leq n$, prove $\mathbb{E}(U_n)=(n-1)pq$, and find the variance of $U_n$.

I was able to solve this question, only calculating the variance didn't work. I think it's best to use $$\mathrm{Var}(U_n)=\mathbb{E}(U_n^2)-\mathbb{E}(U_n)^2,$$ because the second expectation is already calculated. However, I have no idea how to calculate $\mathbb{E}(U_n^2)$. Can anyone provide some help? 
EDIT:
By the way, the variance should be $\mathrm{Var}(U_n)=(n-1)pq-(3n-5)(pq)^2$, so the second moment of $U_n$ should be $(n-1)pq+(n-3)(n-2)(pq)^2$. Still, I have no clue how to calculate this second moment. 
EDIT 2:
Using Dean's answer, I tried solving for the variance. We have a random sum for the amount of zeros in $\{2,3,\ldots,n\}$, which has a binomial distribution with parameters $n-1$ and $q$. Then we obtain in total $j$ zero's, which can be preceded by ones. The preceding elements follow a Bernoulli distribution with parameter $p$. Thus, we can set up the probability generating functions to obtain:
\begin{eqnarray}
G_{zero's}(s) & = & (p+qs)^{n-1}\\
G_{ones}(s) & = &q+ps\\
G_{U_n}(s) & = & G_{zero's}(G_{ones}(s))=(p+q(q+ps))^{n-1}\\
G_{U_n}'(s) & = & (n-1)(p+q(q+ps))^{n-2}pq\\
G_{U_n}''(s) & = & (n-1)(n-2)(p+q(q+ps))^{n-3}(pq)^2\\
\mathrm{Var}(U_n) & = & G_{U_n}''(1)+G_{U_n}'(1)-G_{U_n}'(1)^2\\
& = & (n-1)(n-2)(pq)^2+(n-1)pq-(n-1)^2(pq)^2\\
& = & (n-1)pq+(n-1)(n-2-n+1)(pq)^2\\
& = & (n-1)pq-(n-1)(pq)^2.
\end{eqnarray}
However, the answer for this question says that the variance should be $\mathrm{Var}(U_n)=(n-1)pq-(3n-5)(pq)^2$, and since this is an old Oxford examination question, it seems unlikely that their answer is wrong. Also, the probability generating function seems allright, since $G_{U_n}'(1)$ indeed yields $\mathbb{E}(X)$.
Any ideas on where I can have made a mistake? It seems also strange to me that we determine a random sum which can yield at most $n-1$ zero's, and then treat this like every one of these zeros can have a preceding one. For example, when all tosses yield a zero, we know for sure that $U_n=0$, while the above implies that we have $n-1$ Bernoulli trials, so quite likely $U_n\neq 0$. How to fix this?
 A: Let $T_i=1$ if $Z_i=1$ and $Z_{i+1}=0$  and $0$ otherwise. Note that $ET_i=pq$ and that $T_i T_{i+1} = 0.$ Then $U_n=\sum_{i=1}^{n-1}T_i$ and $$\mathrm{Var}(U_n) = \sum_{i=1}^{n-1}\mathrm{Var}(T_i) + 2 \sum_{i=1}^{n-2}\sum_{j=i+1}^{n-1} \mathrm{Cov}(T_i,T_j)$$
$$ = (n-1)\,\mathrm{Var}(T_1) + 2(n-2)\,\mathrm{Cov}(T_1,T_2),$$
by symmetry and by observing that $\mathrm{Cov}(T_i,T_j) = 0$ if the set $\{i,i+1\}\cap\{j,j+1\}=\phi.$
But  $\mathrm{Var}(T_1)=ET_1^2 - (ET_1)^2= pq(1-pq),$ and $\mathrm{Cov}(T_1,T_2)=E(T_1 T_2)-(pq)^2 = -(pq)^2$ since $T_1T_2=0.$ 
So $$\mathrm{Var}(U_n) = (n-1)pq(1-pq) - 2(n-2)(pq)^2.$$
A: The following is an incorrect treatment (incorrectly assuming independence)... just leaving in place for reference.
Let $J$ be the number of zeros in the sequence, not counting the first element. $J$ is binomial with $n-1$ trials and probability q.
For a sample with $j$ zeros beyond the first element, the number that precede the zero with a one is $U$ which is binomial with $j$ trials and probability p.
The pmf for U is therefore given by:
$$f(u) = \sum_{j=0}^{n-1} B(j|n-1,q)B(u|j,p)$$
From that you can work out the second moment.
A: A correct approach would be to use the "run test", which counts the number of runs in a two-state sequence as a test of the independence of the elements of the sequence. Use the "run test" pmf for the number of runs $R$, given $n$ and $p$. Each time a run of ones end, you have satisfied the condition $A$. The pmf for $U$ is found by considering that $R=U/2$. Alternatively you could use $E[R]$ and $V[R]$ directly to find $E[U]$ and $E[U]$.
Here is one site that explains how to derive the pmf for the run test:
https://onlinecourses.science.psu.edu/stat414/book/export/html/233
