Check undefined before deleting