diff --git a/Modules/Learning/Supervised/include/otbCvRTreesWrapper.h b/Modules/Learning/Supervised/include/otbCvRTreesWrapper.h
index 6175b1f46225b7c924390d2b8e7d3bcff5a50e4a..47f4560293717df9e2da1693069924b08c659901 100644
--- a/Modules/Learning/Supervised/include/otbCvRTreesWrapper.h
+++ b/Modules/Learning/Supervised/include/otbCvRTreesWrapper.h
@@ -20,13 +20,29 @@
 
 #include "otbOpenCVUtils.h"
 #include <vector>
+#include <algorithm>
 
+
+namespace otb
+{
+
+/** \class CvRTreesWrapper
+ * \brief Wrapper for OpenCV Random Trees
+ *
+ * \ingroup OTBSupervised
+ */
 class CV_EXPORTS_W CvRTreesWrapper : public CvRTrees
 {
 public:
   CvRTreesWrapper(){};
   virtual ~CvRTreesWrapper(){};
   
+  /** Predict the confidence of the classifcation by computing the 
+      difference in votes between the first and second most voted classes.
+      This measure is preferred to the proportion of votes of the majority
+      class, since it provides information about the conflict between the
+      most likely classes.
+  */
   float predict_confidence(const cv::Mat& sample, 
                            const cv::Mat& missing = 
                            cv::Mat()) const
@@ -39,16 +55,15 @@ public:
       CV_Assert( 0 <= class_idx && class_idx < nclasses );
       ++classVotes[class_idx];
       }
+    // We only sort the 2 greatest elements
     std::nth_element(classVotes.begin(), classVotes.begin()+1, 
                      classVotes.end(), std::greater<>());
-    unsigned int maxVotes = classVotes[0];
-    unsigned int secondVotes = classVotes[1];
-    float confidence = static_cast<float>(maxVotes-secondVotes)/ntrees;
+    float confidence = static_cast<float>(classVotes[0]-classVotes[1])/ntrees;
     return confidence;
   };
 
 };
 
-
+}
 
 #endif