refactoring, caching containsVar for compoundterm