move rewriter outside