code for hasNext