Reworked terminal functions, working towards removing the
need for global variables.