much refactoring, some reordering, a hint of fixing, a few new functions including the TermTransformer, which leads to an infinite loop - needs fixing