Fix some issues with the grouping commands, and greatly expand test coverage