Clean up TermUI some (and test it)