Some bug fixes to rewrite