Fix a bug in distance.