I think the implementation is less confusing this way (it's convoluted enough as it is).
However, you were on to something here because I forgot to reset the node IDs after constructing the new mesh.