Fix possible NoSuchElementException.