Refactor the build script