ensure that the generator is valid before calling next
Merge pull request #5 from krtek4/bugfix

ensure that the generator is valid before calling next