Added hasnext function