Fixing detach logic