Calculating the covariance