Fix bug when iterating more than twice