Added covariance calculation and covariance matrix construction