Fixed Python3 incompatible iterator usage