nearquery test and bugfix