Made gen.py shorter and more readable.