Refactor `group by` to make it more readable.