Fixed crash caused by faulty use of iterator