Finnish the function nearest.
Code clean up