Big monad refactor.

Now the signature is abstracted over a MonadTerm, which cuts down
on the wrappers for TC.