Expanded rewriter
Simplified code