first refactor almost done -- separation of GUI and noGUI modes. small details/bugs left to be fixed.