generic rewrite