fixed infinite loop, memory leaks
Added code attempting to remove duplicates by reversing and reordering
the history in Node::walk, but for some reason it still adds them.