Moved from `close()` so that all closing/detaching/disconnecting is funneled through here.