Fixed VM problem plus code reorg