bug in a generator code