Isn't this Commentz-Walter algorithm buggy?
I figured it out, you have to reset v to root at the same time as you reset j to 0 (in fact if you just add depth to your node, you can skip j and just use v.depth)