diff --git a/Geo/MHexahedron.cpp b/Geo/MHexahedron.cpp
index 3f73d503eef00f37e87341480415f9dadd791984..ce6d4f139b05c3b9ab8cc042bcc438fe073c9b9d 100644
--- a/Geo/MHexahedron.cpp
+++ b/Geo/MHexahedron.cpp
@@ -438,20 +438,20 @@ int MHexahedron::getNumFacesRep(bool curved)
 
 int MHexahedron20::getNumFacesRep(bool curved)
 {
-  return curved ? 6 * (CTX::instance()->mesh.numSubEdges *
-                       CTX::instance()->mesh.numSubEdges * 2) : 12;
+  return curved ? 12 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) :
+         MHexahedron::getNumFacesRep(curved);
 }
 
 int MHexahedron27::getNumFacesRep(bool curved)
 {
-  return curved ? 6 * (CTX::instance()->mesh.numSubEdges *
-                       CTX::instance()->mesh.numSubEdges * 2) : 12;
+  return curved ? 12 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) :
+         MHexahedron::getNumFacesRep(curved);
 }
 
 int MHexahedronN::getNumFacesRep(bool curved)
 {
-  return curved ? 6 * (CTX::instance()->mesh.numSubEdges *
-                       CTX::instance()->mesh.numSubEdges * 2) : 12;
+  return curved ? 12 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) :
+         MHexahedron::getNumFacesRep(curved);
 }
 
 void _getIndicesReversedHex(int order, indicesReversed &indices)
diff --git a/Geo/MPrism.cpp b/Geo/MPrism.cpp
index caa99c36c6889dfa1d7463fa7605052a222a686e..38306fe013514ce6801f96b681da6343bb3757f8 100644
--- a/Geo/MPrism.cpp
+++ b/Geo/MPrism.cpp
@@ -496,20 +496,20 @@ int MPrism::getNumFacesRep(bool curved)
 
 int MPrism15::getNumFacesRep(bool curved)
 {
-  return curved ? 4 * (CTX::instance()->mesh.numSubEdges *
-                       CTX::instance()->mesh.numSubEdges * 2) : 8;
+  return curved ? 8 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) :
+         MPrism::getNumFacesRep(curved);
 }
 
 int MPrism18::getNumFacesRep(bool curved)
 {
-  return curved ? 4 * (CTX::instance()->mesh.numSubEdges *
-                       CTX::instance()->mesh.numSubEdges * 2) : 8;
+  return curved ? 8 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) :
+         MPrism::getNumFacesRep(curved);
 }
 
 int MPrismN::getNumFacesRep(bool curved)
 {
-  return curved ? 4 * (CTX::instance()->mesh.numSubEdges *
-                       CTX::instance()->mesh.numSubEdges * 2) : 8;
+  return curved ? 8 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) :
+         MPrism::getNumFacesRep(curved);
 }
 
 static void _addEdgeNodes(int num, bool reverse, int order,
diff --git a/Geo/MPyramid.cpp b/Geo/MPyramid.cpp
index 457a7f952a21aa7e4e333f5e8523f026331035e9..73ee2fe9aadc096751f7d0f0ade22fd61eb5990e 100644
--- a/Geo/MPyramid.cpp
+++ b/Geo/MPyramid.cpp
@@ -97,7 +97,8 @@ int MPyramidN::getNumFacesRep(bool curved)
 {
   // FIXME: remove !getIsAssimilatedSerendipity() when serendip are implemented
   return (curved && !getIsAssimilatedSerendipity()) ?
-    6 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) : 6;
+         6 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) :
+         MPyramid::getNumFacesRep(curved);
 }
 
 static void _myGetFaceRep(MPyramid *pyr, int num, double *x, double *y, double *z,
diff --git a/Geo/MQuadrangle.cpp b/Geo/MQuadrangle.cpp
index 9a2d1f07239b51fab31cc5eb0ffcb46e434ef283..b552a504ca0633f419d0909d755035d5f6f0ef05 100644
--- a/Geo/MQuadrangle.cpp
+++ b/Geo/MQuadrangle.cpp
@@ -17,8 +17,6 @@
 
 #include <cstring>
 
-#define SQU(a)      ((a)*(a))
-
 void MQuadrangle::getEdgeRep(bool curved, int num, double *x, double *y, double *z,
                              SVector3 *n)
 {
@@ -137,17 +135,20 @@ int MQuadrangle::getNumFacesRep(bool curved)
 
 int MQuadrangleN::getNumFacesRep(bool curved)
 {
-  return curved ? 2*SQU(CTX::instance()->mesh.numSubEdges) : 2;
+  return curved ? 2 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) :
+         MQuadrangle::getNumFacesRep(curved);
 }
 
 int MQuadrangle8::getNumFacesRep(bool curved)
 {
-  return curved ? 2*SQU(CTX::instance()->mesh.numSubEdges) : 2;
+  return curved ? 2 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) :
+         MQuadrangle::getNumFacesRep(curved);
 }
 
 int MQuadrangle9::getNumFacesRep(bool curved)
 {
-  return curved ? 2*SQU(CTX::instance()->mesh.numSubEdges) : 2;
+  return curved ? 2 * gmsh_SQU(CTX::instance()->mesh.numSubEdges) :
+         MQuadrangle::getNumFacesRep(curved);
 }
 
 static void _myGetFaceRep(MQuadrangle *t, int num, double *x, double *y, double *z,
diff --git a/Mesh/meshGEdge.cpp b/Mesh/meshGEdge.cpp
index d333e2a286cecd925fe0625959b3f18d7da3931f..72fbcfa2f73189279ce29b69ce2bf449b22dc1b1 100644
--- a/Mesh/meshGEdge.cpp
+++ b/Mesh/meshGEdge.cpp
@@ -405,7 +405,13 @@ static void filterPoints(GEdge*ge, int nMinimumPoints)
     v->getParameter(0,t);
     if (i != 0){
       double t0;
-      v0->getParameter(0,t0);
+      if (v0->onWhat()->dim() == 0){
+        // Vertex is begin point
+        t0 = ge->parFromPoint(SPoint3(v0->x(), v0->y(), v0->z()));
+      }
+      else
+        v0->getParameter(0, t0);
+
       t=0.5*(t+t0);
     }
     double lc = F_LcB(ge, t);
diff --git a/Mesh/qualityMeasuresJacobian.cpp b/Mesh/qualityMeasuresJacobian.cpp
index 2742a079780a064ee168a0c08c8d679246bf85de..b73bdc3a22b7692e7883df92e01c58ecc0141182 100644
--- a/Mesh/qualityMeasuresJacobian.cpp
+++ b/Mesh/qualityMeasuresJacobian.cpp
@@ -48,29 +48,27 @@ static inline void computeCoeffLengthVectors_(const fullMatrix<double> &mat,
                               pow_int(mat(i, 4), 2) +
                               pow_int(mat(i, 5), 2)  );
     }
-    if (mat.size2() > 6) { // if 3D
+    if (type == TYPE_TRI) {
+      for (int i = 0; i < sz1; i++) {
+        coeff(i, 2) = std::sqrt(pow_int(mat(i, 3) - mat(i, 0), 2) +
+                                pow_int(mat(i, 4) - mat(i, 1), 2) +
+                                pow_int(mat(i, 5) - mat(i, 2), 2)  );
+      }
+    }
+    else if (type != TYPE_QUA) { // if 3D
       for (int i = 0; i < sz1; i++) {
         coeff(i, 2) = std::sqrt(pow_int(mat(i, 6), 2) +
                                 pow_int(mat(i, 7), 2) +
                                 pow_int(mat(i, 8), 2)  );
       }
     }
-    else if (type == TYPE_TRI) {
+    if (type == TYPE_TET || type == TYPE_PRI) {
       for (int i = 0; i < sz1; i++) {
-        coeff(i, 2) = std::sqrt(pow_int(mat(i, 3) - mat(i, 0), 2) +
+        coeff(i, 3) = std::sqrt(pow_int(mat(i, 3) - mat(i, 0), 2) +
                                 pow_int(mat(i, 4) - mat(i, 1), 2) +
                                 pow_int(mat(i, 5) - mat(i, 2), 2)  );
       }
     }
-    switch (type) {
-      case TYPE_TET:
-      case TYPE_PRI:
-        for (int i = 0; i < sz1; i++) {
-          coeff(i, 3) = std::sqrt(pow_int(mat(i, 3) - mat(i, 0), 2) +
-                                  pow_int(mat(i, 4) - mat(i, 1), 2) +
-                                  pow_int(mat(i, 5) - mat(i, 2), 2)  );
-        }
-    }
     if (type == TYPE_TET) {
       for (int i = 0; i < sz1; i++) {
         coeff(i, 4) = std::sqrt(pow_int(mat(i, 6) - mat(i, 0), 2) +
diff --git a/contrib/HighOrderMeshOptimizer/BoundaryLayerCurver.h b/contrib/HighOrderMeshOptimizer/BoundaryLayerCurver.h
index aabcec0ba89a11233af06dfbfa034ef76502a874..3ec7e9ea0c969d47c072e340eb35387c3cf27c61 100644
--- a/contrib/HighOrderMeshOptimizer/BoundaryLayerCurver.h
+++ b/contrib/HighOrderMeshOptimizer/BoundaryLayerCurver.h
@@ -31,6 +31,7 @@
 #define _BOUNDARYLAYERCURVER_H_
 
 //#include <map>
+#include <algorithm>
 #include <list>
 
 #include "MEdge.h"
diff --git a/doc/texinfo/gmsh.texi b/doc/texinfo/gmsh.texi
index f645649b3bb3455828860c32ce8e6df91e2fa633..ba04d5467d2cbf2f847c15cd363a71426936a22c 100644
--- a/doc/texinfo/gmsh.texi
+++ b/doc/texinfo/gmsh.texi
@@ -3444,8 +3444,8 @@ being stored in @var{list-of-coords}). Defining @var{g}[@var{i}] =
 Sum(@var{j}=0, ..., @var{m}-1) @var{G}[@var{i}][@var{j}]
 @var{q}[@var{j}], with @var{q}[@var{j}] = @var{u}^@var{Q}[@var{j}][0]
 @var{v}^@var{Q}[@var{j}][1] @var{w}^@var{Q}[@var{j}][2], then
-@var{val-coef-matrix} denotes the @var{m} x @var{m} matrix @var{G} and
-@var{val-exp-matrix} denotes the @var{m} x @var{3} matrix @var{Q}.
+@var{geo-coef-matrix} denotes the @var{m} x @var{m} matrix @var{G} and
+@var{geo-exp-matrix} denotes the @var{m} x @var{3} matrix @var{Q}.
 
 Here are for example the interpolation matrices for a first order
 quadrangle: