private void nearest_knn(KDNode node, double[] targetPoint) {
		tryToSave(node, targetPoint); 
		
		int dMinus1 = node.d-1;
		if(dMinus1 < 0){
			dMinus1 = dimensionCount - 1;
		}
		
		double perpendicularDistance = Math.abs(node.values[node.d] - targetPoint[dMinus1]);
		if (perpendicularDistance < resultKNN.maximum().distance) { 
			// explore the "above" and "below" branches.
			if (node.above != null) {
				nearest_knn(node.above, targetPoint);
			}
			if (node.below != null) {
				nearest_knn(node.below, targetPoint);
			}
		} else {
			// explore one side of the tree.
			if (targetPoint[dMinus1] < node.values[node.d]) {
				if (node.below != null) {
					nearest_knn(node.below, targetPoint);
				}
			} else {
				if (node.above != null) {
					nearest_knn(node.above, targetPoint);
				}
			}
		}
	}