I'm having trouble understanding what is done in the following step in the derivation of the formula for the slope of the sample regression line presented in Gujarati's Basic Econometrics, 5th edition, pg. 58 :
\begin{align} \hat{\beta_2}&=\frac{n\sum{X_iY_i}-\sum{X_i}\sum{Y_i}}{n\sum{X^2_i}-(\sum{X_i})^2}\\ &=\frac{\sum{(X_i-\bar{X})(Y_i-\bar{Y})}}{\sum{(X_i-\bar{X})^2}}\\ \end{align}
How exactly does the first equality turn into the second? Thanks very much in advance.
Note that the denominator is just variance and the numerator covariance. You'll need to review your definitions.