fixed bug in distance measure