This question is from statistical mechanics. My reason for asking it here is because I am confused about how to take the second derivative of the natural log of the partition function $Z$ which is defined as $$Z=\sum\limits_j e^{-\epsilon_j \beta}$$ where $\epsilon_j$ is the total energy of the $j^{\text{th}}$ microstate and the thermodynamic beta defined as $\beta=\frac{1}{k_B T}$ where $T$ is thermodynamic temperature and $k_B$ is Boltzmanns' constant.
I need to show that $$\langle E^2 \rangle =\frac{\partial^2 \ln Z}{\partial \beta^2}=\frac{\partial }{\partial\beta}\frac{1}{Z}\frac{\partial Z}{\partial \beta}=\frac{1}{Z}\frac{\partial^2 Z}{\partial \beta^2}-\frac{1}{Z^2}\left(\frac{\partial Z}{\partial \beta}\right)^2\tag{1}$$
I have already been looking at this similar question but it doesn't quite answer my question.
My attempt:
I understand that $$\frac{\partial^2 \ln Z}{\partial \beta^2}=\frac{\partial }{\partial\beta}\frac{1}{Z}\frac{\partial Z}{\partial \beta}$$
since $$\frac{\partial^2 \ln Z}{\partial \beta^2}=\frac{\partial }{\partial\beta}\left(\frac{\frac{\partial}{\partial \beta}\left[\ln\left(\sum\limits_j e^{-\epsilon_j \beta}\right)\right]}{\sum\limits_j e^{-\epsilon_j \beta}}\right)=\frac{\partial }{\partial\beta}\left(\frac{\frac{\partial}{\partial \beta}\left[\ln\left(Z\right)\right]}{Z}\right)=\frac{\partial }{\partial\beta}\frac{1}{Z}\frac{\partial Z}{\partial \beta}$$
But a problem arises when I try to take the second derivative:
So I apply the product rule
$$\frac{\partial^2 \ln Z}{\partial \beta^2}=\frac{\partial }{\partial\beta}\left(\frac{1}{Z}\frac{\partial Z}{\partial \beta}\right)=-\frac{1}{Z^2}\frac{\partial Z}{\partial \beta}+\frac{1}{Z}\frac{\partial^2 Z}{\partial \beta^2}$$
Which is clearly not equal to the leftmost expression in $(1)$.
Could someone please show/explain to me how to reach equation $(1)$?
Kindest regards.