Major reorg of the code

Broke the different tern capabilities into their own module