Added check for accuracy in distance function