implementing distance