Clean up stats handling, make more readable