Replacing delete by detach