created closure function for finding distance on single line