The problem dies in the second loop, which did not remove the last few strings as I thought.