Added implementation of distance method