Refactors generate.py