working rewrite