finally fixed bug with distalnces