refactoring, using the awesome group_by method