fixing infinite loop when use multiple groups