Moved distance computation to its own file