use indices instead of iterators that can go bad when list goes out of scope