rewrite working