Fixed crashes resulting from deleting objects multiple times due to using shared_ptr incorrectly