Fixes to compute_total_stats function