More sys_rewrite stuff, including proper error handling for VMs