Added option to specify number of groups rather than number in each group.