Added some nearest neighbor code.