Added the feature to group the elements by state (only one can be in the specified state)