Do not access vm.libvirt_domain after it being already removed - this will redefine it again in libvirt, just to undefine it in a moment. On the other hand, few lines below there is fallback libvirt cleanup, in case of proper one not working.