aqsa's code for distance(new)