Cleaned up code. Mean values still do not match  the expected values given by the