Checks if db is null before deleting