refactoring to allow both GUI and Console based UI