Fix iterating over a linked list so we don't lose track of the first element

I don't know what sort of brainfart happened in my initial version
Merge Pull Request #330 into next

* pr/330:
  Fix iterating over a linked list so we don't lose track of the first element