More careful string handling.
Add nearest-search functions to demo program.