Iterate over a copy of the parents container since we are removing elements from the original.
Merge pull request #4209 from paperbagcorner/fix-forloop

Iterate over a copy of the parents container since we are removing elements from the original