Tweaked unexpected stop algorithm.