Fixed minor bug: sign error in distance function