Bugfix: correctly terminate grouping