fixed mean and variance calculation
added derivative, changed function for mean and variance