Fix an incorrect index check that prevented subgroups to work for groups with shared variables.