Refactor build.py