proper distance calculation