I re-wrote the term re-writing system and wrote a few test cases for
it.
Merge branch 'master' into output-format