refactor moving average function. entire code will be redone.