Distance calculation bugfix.