CURATOR-131 use iterator.remove instead of foreach

When iterating over a collection, if we try to remove elements that
can lead to undefined behaviour. We should use an iterator and its
remove method to do this safely.