implemented database querying by distance and tests