Preventing a crash when deleting entities