Refactored to create HistoryBuffer class that encapsulates the lines of history that are kept