Refactor stats handling