Improved rewriter; added fold operation.