updated logic for required groups to handle the various states of selected elements