updated exiting conditions