fixed rewrite bug