support for more than 2 groups at beginning