Modified to compute covariance and mahalanobis distance