Fixed a bug that is caused by iterators in python3.
Changed handling.