Added check to short circuit the outer loop as well