move rewrite to utils