Rewrite bug fix