the bug causing the hangup is somewhere in generate()