fixed race condition in exit checking