Refactoring statistics function