implemented covariance calculation