Changed iterator to generator