fix exceptions when deleting keys and instance