Move add/remove group calls out of a loop