Fix error in distance queries.