Edited code to use next() method to get next value from generator.