@heathd refactored the code to use group_by