fixed bug in iterating list