Iterate on a copy
Remove the list casting
Correct the iteration
Complete Py3 compatibility fixes.