Fixed bug which was causing a null pointer when a detached object was being removed