added calculateMovingAverage method