Improve handling of detached nodes in a node collection
Make tests pass
Added extra test