Fix stream iteration bug