Refactor build scripts