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