added exit condition for gui.