Continuing working on Distance function