Used next(gen) rather than gen.__next__() to support Python 2 too

Thank you vasilcovsky for the suggestion