fix some bug when distance is -1