Switched the loop from while to iter()