added distance code and lib