added sugar for vm

this allows removing iframe in the browser version when the simulation
ends
added calls to free() when the simulation ends