don’t call the total_ratings() function again - use the results already returned in $stats['total_rates'].