checking if group is changed before adding new element
simplified solution1