I think it should use a seperate iterator in the while. You do need to free here afaik.