Fixed issues caused by deleting related objects