Improved End-of-generator control flow
Finally tracked down and fixed segfault bug.