new code for rewrite