fixed a potential bug with iterators