first version of distance method