Fixed bug in the rewrite