fix covariance calculation