Fix errors in rewrite