added new function for calculating distance