Performing a moving-average calculation