Move the cleanup before terminating the script in case of broken objects.