refactored moving avg to take a sample size