Completed move of code in vm.c to functions for reuse from compiled code.