finished rewrite