added covariance
removed some redundant lines of code