Fixed a delete-detach bug