Refactoring main.py and build script