fix order of dist calc