Element grouping in realms.
Some refactoring.