gen.py improved