rewrite logics