added compute nearest nieghbor, indented for readability, and maintenance