Fixed error in nearest neighbor calcs