fix a small bug in TrainVM & calculate the distance