fix dangling pointer issue. If the node being processed is replaced,