Refactor record_generation_stats()