Simplify CLI code by creating Streams class

Greatly simplifies the code in the main loop  by moving all of the
stream-handling code into a separate class.