diff --git a/Mesh/meshGFaceRecombine.cpp b/Mesh/meshGFaceRecombine.cpp
index 016556ed7010195739ac903a78276b8643941739..35e706ae9582df3718b491eb42c724cae6b1e9b2 100644
--- a/Mesh/meshGFaceRecombine.cpp
+++ b/Mesh/meshGFaceRecombine.cpp
@@ -16,6 +16,7 @@
 #include "meshGFaceRecombine.h"
 #include "MTriangle.h"
 #include "MQuadrangle.h"
+#include "PView.h"
 #ifdef REC2D_SMOOTH
   #include "meshGFaceOptimize.h"
 #endif
@@ -802,14 +803,14 @@ void Rec2DData::revertAssumedParities()
 double Rec2DData::getGlobalValue()
 {
   double a = (_current->_valVert) / (_current->_numVert);
-  return a * (_current->_valEdge) / (_current->_numEdge);
+  return a *a* (_current->_valEdge) / (_current->_numEdge);
 }
 
 double Rec2DData::getGlobalValue(int numEdge, double valEdge,
                                    int numVert, double valVert)
 {
   double a = (_current->_valVert + valVert) / (_current->_numVert + numVert);
-  return a * (_current->_valEdge + valEdge) / (_current->_numEdge + numEdge);
+  return a *a* (_current->_valEdge + valEdge) / (_current->_numEdge + numEdge);
 }
 
 Rec2DAction* Rec2DData::getBestAction()
@@ -847,16 +848,26 @@ bool Rec2DData::isOutOfDate(Rec2DAction *ra)
 
 void Rec2DData::drawEndNode(int num)
 {
-  /*std::list<Rec2DNode*>::iterator it = _endNodes.begin();
-  for (int i = 0; i < num && it != _endNodes.end(); ++i, ++it) {
+  for (unsigned int i = 0; i < num && i < _current->_endNodes.size(); ++i) {
     std::map<int, std::vector<double> > data;
-    Rec2DNode *currentNode = *it;
-    
-    for (unsigned int i = 0; i < invalids.size(); ++i)
-      computeMinMax(&invalids[i], 1, &data);
-    
+    Rec2DNode *currentNode = _current->_endNodes[i];
+    Msg::Info("%d -> %g", i+1, currentNode->getGlobVal());
+    while (currentNode && currentNode->getAction()) {
+      /*Msg::Info("%d",currentNode);
+      Msg::Info("%d",currentNode->getAction());
+      Msg::Info(" ",currentNode);*/
+      data[currentNode->getNum()].push_back(currentNode->getGlobVal());
+      currentNode = currentNode->getFather();
+    }
+    new PView("Jmin_bad", "ElementData", Recombine2D::getGFace()->model(), data);
   }
-  new PView("Jmin_bad", "ElementData", _m, data);*/
+}
+
+void Rec2DData::sortEndNode()
+{
+  Msg::Info("sort %g", (*_current->_endNodes.begin())->getGlobVal());
+  std::sort(_current->_endNodes.begin(), _current->_endNodes.end(), moreRec2DNode());
+  Msg::Info("sort %g", (*_current->_endNodes.begin())->getGlobVal());
 }
 
 /**  Rec2DAction  **/
@@ -1097,6 +1108,17 @@ void Rec2DTwoTri2Quad::getElements(std::vector<Rec2DElement*> &elem)
   elem.push_back(_triangles[1]);
 }
 
+int Rec2DTwoTri2Quad::getNum()
+{
+  MQuadrangle *quad = new MQuadrangle(_vertices[0]->getMVertex(),
+                                      _vertices[2]->getMVertex(),
+                                      _vertices[1]->getMVertex(),
+                                      _vertices[3]->getMVertex());
+  Recombine2D::add(quad);
+  return quad->getNum();
+}
+
+
 /**  Rec2DEdge  **/
 /*****************/
 Rec2DEdge::Rec2DEdge(Rec2DVertex *rv0, Rec2DVertex *rv1)
@@ -1888,20 +1910,37 @@ MQuadrangle* Rec2DElement::_createQuad() const
 
 /**  Rec2DNode  **/
 /*****************/
-/*bool lessRec2DNode::operator()(Rec2DNode *rn1, Rec2DNode *rn2) const
+bool lessRec2DNode::operator()(Rec2DNode *rn1, Rec2DNode *rn2) const
 {
   return *rn1 < *rn2;
 }
 
- */Rec2DNode::Rec2DNode(Rec2DNode *father, Rec2DAction *ra, double &bestEndGlobVal)
+bool greaterRec2DNode::operator()(Rec2DNode *rn1, Rec2DNode *rn2) const
+{
+  return *rn2 < *rn1;
+}
+
+bool moreRec2DNode::operator()(Rec2DNode *rn1, Rec2DNode *rn2) const
+{
+  if (rn1->getNumTri() == rn2->getNumTri())
+    return *rn2 < *rn1;
+  return rn1->getNumTri() < rn2->getNumTri();
+}
+
+Rec2DNode::Rec2DNode(Rec2DNode *father, Rec2DAction *ra, double &bestEndGlobVal)
 : _father(father), _ra(ra), _globalValue(.0), _bestEndGlobVal(.0)
 {
   _son[0] = NULL;
   _son[1] = NULL;
   _son[2] = NULL;
   Rec2DElement *newElement;
-  if (_ra)
+  if (_ra) {
     _ra->choose(newElement);
+    _remainingTri = father->getNumTri() - _ra->getNumElement();
+  }
+  else
+    _remainingTri = Rec2DData::getNumElement();
+  
   
   _globalValue = Rec2DData::getGlobalValue();
   
@@ -1925,3 +1964,8 @@ MQuadrangle* Rec2DElement::_createQuad() const
     _ra->unChoose(newElement);
 }
 
+bool Rec2DNode::operator<(Rec2DNode &other)
+{
+  return _globalValue < other._globalValue;
+}
+
diff --git a/Mesh/meshGFaceRecombine.h b/Mesh/meshGFaceRecombine.h
index bff0cd36c73265312a0420865bdcfba183804a80..66cf4fcc9a32409741a8487c6ddc57bc710c7345 100644
--- a/Mesh/meshGFaceRecombine.h
+++ b/Mesh/meshGFaceRecombine.h
@@ -18,6 +18,7 @@
 #include "BackgroundMesh.h"
 //#include "GModel.h"
 //#include "MEdge.h"
+#include "MQuadrangle.h"
 
 class Rec2DNode;
 class Rec2DVertex;
@@ -25,6 +26,15 @@ class Rec2DEdge;
 class Rec2DElement;
 class Rec2DAction;
 class Rec2DData;
+struct lessRec2DNode {
+  bool operator()(Rec2DNode*, Rec2DNode*) const;
+};
+struct greaterRec2DNode {
+  bool operator()(Rec2DNode*, Rec2DNode*) const;
+};
+struct moreRec2DNode {
+  bool operator()(Rec2DNode*, Rec2DNode*) const;
+};
 
 //typedef std::list<Rec2DAction*> setofRec2DAction;
 //typedef std::map<MVertex*, Rec2DVertex*> mapofVertices;
@@ -53,6 +63,7 @@ class Recombine2D {
     static inline GFace* getGFace() {return _current->_gf;}
     static inline int getNumChange() {return _current->_numChange;}
     static inline backgroundMesh* bgm() {return _current->_bgm;}
+    static void add(MQuadrangle *q) {_current->_gf->quadrangles.push_back(q);}
     
   private :
     double _geomAngle(MVertex*,
@@ -65,7 +76,7 @@ class Recombine2D {
 class Rec2DData {
   private :
     int _numEdge, _numVert;
-    double _valEdge, _valVert;
+    long double _valEdge, _valVert;
     static Rec2DData *_current;
     
     std::set<Rec2DEdge*> _edges;
@@ -73,7 +84,7 @@ class Rec2DData {
     std::set<Rec2DElement*> _elements, _hiddenElements;
     
     std::list<Rec2DAction*> _actions;
-    std::list<Rec2DNode*> _endNodes;
+    std::vector<Rec2DNode*> _endNodes;
     
     std::map<int, std::vector<Rec2DVertex*> > _parities;
     std::map<int, std::vector<Rec2DVertex*> > _assumedParities;
@@ -89,19 +100,22 @@ class Rec2DData {
     std::vector<MQuadrangle*> _quad;
 #endif
     
-    static double getNumEndNode() {return _current->_endNodes.size();}
+    static int getNumEndNode() {return _current->_endNodes.size();}
+    static int getNumElement() {return _current->_elements.size();}
     
     static double getGlobalValue();
     static double getGlobalValue(int numEdge, double valEdge,
                                  int numVert, double valVert );
     static inline void addVert(int num, double val) {
       _current->_numVert += num;
-      _current->_valVert += val;
+      _current->_valVert += (long double)val;
+    }
+    static inline void addValVert(double val) {
+      _current->_valVert += (long double)val;
     }
-    static inline void addValVert(double val) {_current->_valVert += val;}
     static inline void addEdge(int num, double val) {
       _current->_numEdge += num;
-      _current->_valEdge += val;
+      _current->_valEdge += (long double)val;
     }
     
     static Rec2DAction* getBestAction();
@@ -133,9 +147,7 @@ class Rec2DData {
     static inline void addEndNode(Rec2DNode *rn) {
       _current->_endNodes.push_back(rn);
     }
-    static inline void sortEndNode() {
-      /*_current->_endNodes.sort(lessRec2DNode());*/
-    }
+    static void sortEndNode();
     static inline void drawEndNode(int num);
     static inline void addHidden(Rec2DElement *rel) {
       _current->_hiddenElements.insert(rel);
@@ -185,7 +197,9 @@ class Rec2DAction {
     virtual Rec2DVertex* getVertex(int) = 0;
     virtual void choose(Rec2DElement*&) = 0;
     virtual void unChoose(Rec2DElement*) = 0;
+    virtual inline int getNumElement() = 0;
     virtual void getElements(std::vector<Rec2DElement*>&) = 0;
+    virtual int getNum() = 0;
     
   private :
     virtual void _computeGlobVal() = 0;
@@ -211,7 +225,9 @@ class Rec2DTwoTri2Quad : public Rec2DAction {
     virtual inline Rec2DVertex* getVertex(int i) {return _vertices[i];} //-
     virtual void choose(Rec2DElement*&);
     virtual void unChoose(Rec2DElement*);
+    virtual inline int getNumElement() {return 2;}
     virtual void getElements(std::vector<Rec2DElement*>&);
+    virtual int getNum();
     
   private :
     virtual void _computeGlobVal();
@@ -383,19 +399,24 @@ class Rec2DElement {
     MQuadrangle* _createQuad() const;
 };
 
-/*struct lessRec2DNode {
-  bool operator()(Rec2DNode*, Rec2DNode*) const;
-};
-*/
+
 class Rec2DNode {
   private :
     Rec2DNode *_father;
     Rec2DNode *_son[3];
     Rec2DAction *_ra;
     double _globalValue, _bestEndGlobVal;
+    int _remainingTri;
     
   public :
     Rec2DNode(Rec2DNode *father, Rec2DAction*, double &bestEndGlobVal);
+    
+    bool operator<(Rec2DNode&);
+    inline Rec2DNode* getFather() {return _father;}
+    inline int getNum() {return _ra->getNum();}
+    inline Rec2DAction* getAction() {return _ra;}
+    inline double getGlobVal() {return _globalValue;}
+    inline int getNumTri() {return _remainingTri;}
 };
 
 #endif
\ No newline at end of file