Distance functions are corrected