refactored out StatisticsUtils class and fixed tests