I don't see isgrouped anywhere else. Can we move the logic into the if statement?