calculating distance correctly