general rewrite