Now handles NameError during cleanup.