Refactored the vm