modified the exit condition for unreachable target.