Simplify nearby query and improve join performance

Fixes #217