refactoring for better average