Restore the refactoring to scan_for_exiting() that was lost in a merge.