Some fixes to VirtualMachine