Integrate rewrite into build script
Refine scripts