When removing element, remove it also from group and remove group if it is empty.