implementing calculation of distance - still needs refining