fix detaching so it properly removes nodes and returns the previos node state back