Refactor into term type. Tests.