fixed error in index for distance measurements