rewrite bug fix