fix bugs on mean and difference function