fixed small bug in dist calculation