hasNext() method is refactored