Refactoring of TermContext

**do not review yet**