Initial rewriter refactoring