Refactor build script