Refactor of build script