Improve iterators in for loops

For the three for loops that modify the lists being iterated over, I have added a list() wrapper around the list so that the for loops iterate over a copy of the list while the list is being modified.  Also replaced index in loop with a reference to the iterator.

The current problem is that the lists are being modified as they are being iterated over.

Thanks,

Mark