Long confused wrong data problem gone! Distance function works