fixing all the visible bugs in the covariance matrix calculation scheme