Refactor grouping statement implementations