move prepare_vm logic to client; decompose prepare_vm method into
several smaller methods