fixed a bug in real_distance computation