more efficient computation of the covariance matrix