fixed exiting bug