Fix a bug in hasNextIndex