Corrected NoSuchElementException handling