diff --git a/Geo/MFace.cpp b/Geo/MFace.cpp
index 4ef4dbfa13d3ac13706c1d36a9e07f5c223a07c6..005ba9581ec815cc1304bb28d8a7ab2058ce1ec6 100644
--- a/Geo/MFace.cpp
+++ b/Geo/MFace.cpp
@@ -74,6 +74,7 @@ MFace::MFace(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3)
   }
   else
     _si[3] = 3;
+    
 }
 
 SVector3 MFace::normal() const
diff --git a/Geo/MFace.h b/Geo/MFace.h
index ce8a8b088fa97a76788c0db668cb104b1230d80c..7fce754ffb5227a61602d301f3da2631f064ead6 100644
--- a/Geo/MFace.h
+++ b/Geo/MFace.h
@@ -9,13 +9,14 @@
 #include <functional>
 #include <vector>
 #include "MVertex.h"
+#include "MEdge.h"
 #include "SVector3.h"
 
 // A mesh face.
 class MFace {
  private:
   MVertex *_v[4];
-  char _si[4]; // sorted indices
+  char _si[4]; // sorted indices 
 
  public:
   MFace();
diff --git a/Geo/Makefile b/Geo/Makefile
index 7c84e081cd993ee9f918233e7f8d425bcfbca8ab..1359693f44dc05320d8a2d54457b5d1847f5602c 100644
--- a/Geo/Makefile
+++ b/Geo/Makefile
@@ -10,6 +10,7 @@ LIB = ../lib/libGmshGeo${LIBEXT}
 INC = ${DASH}I../Common ${DASH}I../Geo ${DASH}I../Mesh\
       ${DASH}I../Post ${DASH}I../Numeric ${DASH}I../Parser\
       ${DASH}I../contrib/ANN/include\
+      ${DASH}I../contrib/kbipack\
       ${DASH}I../contrib/MathEval ${DASH}I../contrib/gmm
 
 CFLAGS = ${OPTIM} ${FLAGS} ${INC} ${SYSINCLUDE}
@@ -37,7 +38,9 @@ SRC = GEntity.cpp\
       MElement.cpp\
         MLine.cpp MTriangle.cpp MQuadrangle.cpp MTetrahedron.cpp\
         MHexahedron.cpp MPrism.cpp MPyramid.cpp\
-      MZone.cpp MZoneBoundary.cpp
+      MZone.cpp MZoneBoundary.cpp\
+      CellComplex.cpp
+
 
 OBJ = ${SRC:.cpp=${OBJEXT}}
 
@@ -375,3 +378,5 @@ MPyramid${OBJEXT}: MPyramid.cpp MPyramid.h MElement.h ../Common/GmshDefines.h \
   ../Numeric/Numeric.h ../Numeric/GmshMatrix.h
 MZone${OBJEXT}: MZone.cpp ../Common/GmshConfig.h
 MZoneBoundary${OBJEXT}: MZoneBoundary.cpp ../Common/GmshConfig.h
+CellComplex${OBJEXT}: CellComplex.cpp CellComplex.h 
+  
diff --git a/Makefile b/Makefile
index 9dcb102aaca33a64713a8b66cc18da79e1e16772..36c7086ca76157afb02554fd1617a1bc8abb62e5 100644
--- a/Makefile
+++ b/Makefile
@@ -26,13 +26,16 @@ GMSH_API =\
   Geo/MTetrahedron.h Geo/MHexahedron.h Geo/MPrism.h Geo/MPyramid.h\
   Geo/discreteVertex.h Geo/discreteEdge.h Geo/discreteFace.h Geo/discreteRegion.h\
   Geo/SPoint2.h Geo/SPoint3.h Geo/SVector3.h Geo/SBoundingBox3d.h Geo/Pair.h Geo/Range.h\
+  Geo/CellComplex.h\
+  contrib/kbipack/gmp_normal_form.h contrib/kbipack/gmp_matrix.h contrib/kbipack/gmp_blas.h\
   Numeric/Gauss.h Numeric/FunctionSpace.h Numeric/GmshMatrix.h\
   Numeric/gmshAssembler.h Numeric/gmshTermOfFormulation.h Numeric/gmshLaplace.h\
   Numeric/gmshElasticity.h Numeric/gmshLinearSystem.h Numeric/gmshLinearSystemGmm.h\
   Numeric/gmshLinearSystemFull.h Numeric/gmshFunction.h\
   Post/PView.h Post/PViewData.h Plugin/PluginManager.h\
   Common/VertexArray.h Common/GmshMessage.h\
-  Common/Gmsh.h Common/GmshConfig.h Common/GmshDefines.h Common/GmshVersion.h 
+  Common/Gmsh.h Common/GmshConfig.h Common/GmshDefines.h Common/GmshVersion.h
+
 
 GMSH_EMBEDDED = ${GMSH_API}\
   Geo/GModel.cpp Geo/GModelIO_Mesh.cpp Geo/GEntity.cpp\
diff --git a/configure b/configure
index 334641fefd6e177b928ef7bfe753574a4346131d..2eefd1d2e1cd3949b4edca5c4a0a7fdfadc965d4 100755
--- a/configure
+++ b/configure
@@ -1277,6 +1277,7 @@ Optional Features:
   --enable-chaco          compile Chaco partitioner (default=yes)
   --enable-tetgen         compile Tetgen if available (default=yes)
   --enable-matheval       compile MathEval if available (default=yes)
+  --enable-kbipack        compile kbipack if available (default=yes)
   --enable-gmm            use gmm++ if available (default=yes)
   --enable-osmesa         use OSMesa for offscreen rendering (default=no)
   --enable-cgns           enable CGNS output (default=no)
@@ -1911,6 +1912,11 @@ if test "${enable_matheval+set}" = set; then
   enableval=$enable_matheval;
 fi
 
+# Check whether --enable-kbipack was given.
+if test "${enable_kbipack+set}" = set; then
+  enableval=$enable_kbipack;
+fi
+
 # Check whether --enable-gmm was given.
 if test "${enable_gmm+set}" = set; then
   enableval=$enable_gmm;
@@ -1978,6 +1984,7 @@ if test "x$enable_minimal" = "xyes"; then
   enable_netgen=no;
   enable_tetgen=no;
   enable_matheval=no;
+  enable_kbipack=no;
   enable_gmm=no;
   enable_ann=no;
   enable_metis=no;
@@ -4746,6 +4753,39 @@ _ACEOF
     fi
   fi
 
+    if test "x$enable_kbipack" != "xno"; then
+    { echo "$as_me:$LINENO: checking for ./contrib/kbipack/gmp_normal_form.h" >&5
+echo $ECHO_N "checking for ./contrib/kbipack/gmp_normal_form.h... $ECHO_C" >&6; }
+if test "${ac_cv_file___contrib_kbipack_gmp_normal_form_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  test "$cross_compiling" = yes &&
+  { { echo "$as_me:$LINENO: error: cannot check for file existence when cross compiling" >&5
+echo "$as_me: error: cannot check for file existence when cross compiling" >&2;}
+   { (exit 1); exit 1; }; }
+if test -r "./contrib/kbipack/gmp_normal_form.h"; then
+  ac_cv_file___contrib_kbipack_gmp_normal_form_h=yes
+else
+  ac_cv_file___contrib_kbipack_gmp_normal_form_h=no
+fi
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_file___contrib_kbipack_gmp_normal_form_h" >&5
+echo "${ECHO_T}$ac_cv_file___contrib_kbipack_gmp_normal_form_h" >&6; }
+if test $ac_cv_file___contrib_kbipack_gmp_normal_form_h = yes; then
+  KBIPACK="yes"
+fi
+
+    if test "x${KBIPACK}" = "xyes"; then
+      GMSH_DIRS="${GMSH_DIRS} contrib/kbipack"
+      GMSH_LIBS="${GMSH_LIBS} -lGmshKbi -lgmp"
+      cat >>confdefs.h <<\_ACEOF
+#define HAVE_kbipack 1
+_ACEOF
+
+      BO="${BO} kbipack"
+    fi
+  fi
+
 fi
 
 if test "x${OCC_PREFIX}" != "x"; then
diff --git a/configure.in b/configure.in
index e10e4fc0bbc8147d4d40efa8eb09b4f1f913c900..e253c4745d3fce1557cbb93f99f95cdb63d3371f 100644
--- a/configure.in
+++ b/configure.in
@@ -109,6 +109,9 @@ AC_ARG_ENABLE(tetgen,
 AC_ARG_ENABLE(matheval,
               AC_HELP_STRING([--enable-matheval],
                              [compile MathEval if available (default=yes)]))
+AC_ARG_ENABLE(kbipack,
+              AC_HELP_STRING([--enable-kbipack],
+                             [compile kbipack if available (default=yes)]))
 AC_ARG_ENABLE(gmm,
               AC_HELP_STRING([--enable-gmm],
                              [use gmm++ if available (default=yes)]))
@@ -153,6 +156,7 @@ if test "x$enable_minimal" = "xyes"; then
   enable_netgen=no;
   enable_tetgen=no;
   enable_matheval=no;
+  enable_kbipack=no;
   enable_gmm=no;
   enable_ann=no;
   enable_metis=no;
@@ -500,6 +504,17 @@ if test "x$enable_contrib" != "xno"; then
       BO="${BO} MathEval"
     fi
   fi
+  
+  dnl Check for kbipack
+  if test "x$enable_kbipack" != "xno"; then
+    AC_CHECK_FILE(./contrib/kbipack/gmp_normal_form.h,KBIPACK="yes")
+    if test "x${KBIPACK}" = "xyes"; then
+      GMSH_DIRS="${GMSH_DIRS} contrib/kbipack"
+      GMSH_LIBS="${GMSH_LIBS} -lGmshKbi -lgmp"
+      AC_DEFINE(HAVE_kbipack)
+      BO="${BO} kbipack"
+    fi
+  fi
 
 fi