completes rewrite