Added state groups and migrated code base to use them.