Refactored covariance and mean algorithm to used a HMatrix for linear algebra