Finished code by adding distance calculation into main