fix for counting the correct number of groups