in rewrite, fixed bug where scope is set by a var coming after the original variable