correction to groupIndex algorithm