Fix bug in iterator