Statistics Code Refactored