changed next() to __next__() for python 3 compatibility