more work on rewrite