added distance calculation function