Changing next method of generators to next function, which is supported in both Python 2 and 3.