Added functions to compute covariance matrix.