Tidy nested contexts and reference_terms.