Rewriting: added caching of rewritten nodes.