Solve array index out of bounds probem in nearest_search.
Fix guesses only when needed
Consistent naming