double checked covariance computation

gradient computation is not checked yet....