a bit more fixes to the distance query