generate_stats function moved to stats