Cleanup before starting rewrite