Use an iterator to save memory