refactoring CalculateAverage