Rewrote movingAverage method