Refactored build script