compute covariance matrix more efficient