finished initial rewrite