Added grouping methods. Restored unit tests.