General refactoring and bug fixing.
Add a simple unit test.
A bug sneaked in where the primitive group was uninitialized because of missing
curly brackets.