added separated thread to calculate distance in advance