changed distance implementation again