fixed an insidious error with modifying a set being iterated