Refactor extract group_by_count