group by added to the get_stats() fuction