Refactoring the stats command