Make folding nested defs much faster