fix bugs in generator.py