moving average calculation improvement