Refactor group pattern partitioning.