Avoid NoSuchElementException checking availability of next element