refactor the whole build script