added capability for more than 2 groups