use group_by instead of each_with_object

just simplifies this loop a little bit