Refactor build process