Simplify group_by_prefix.