Computing distances properly