Using squared distance where possible