completed nearest-neighbor, need to check results; TODO: fixed queries