correct bug for calculating moving average