diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp
index 581fa46929cc1a8023fbd6552c5cbd2b65e660c8..7c61c3bbdbdd18a8eada74592879a3e30f0b026b 100644
--- a/Common/CommandLine.cpp
+++ b/Common/CommandLine.cpp
@@ -172,7 +172,15 @@ void Get_Options(int argc, char *argv[])
 
     if(argv[i][0] == '-') {
 
-      if(!strcmp(argv[i] + 1, "")) {
+      if(!strcmp(argv[i] + 1, "socket")) {
+        i++;        
+        if(argv[i] != NULL)
+          CTX.solver.socket_name = argv[i++];
+        else
+	  Msg::Fatal("Missing string");
+        CTX.batch = -3;
+      }
+      else if(!strcmp(argv[i] + 1, "")) {
         CTX.batch = -2;
         i++;
       }
@@ -196,24 +204,16 @@ void Get_Options(int argc, char *argv[])
         CTX.batch = 4;
         i++;
       }
-      else if(!strcmp(argv[i] + 1, "new")) {
-        CTX.files.push_back("-new");
-        i++;
-      }
-      else if(!strcmp(argv[i] + 1, "socket")) {
-        i++;        
-        if(argv[i] != NULL)
-          CTX.solver.socket_name = argv[i++];
-        else
-	  Msg::Fatal("Missing string");
-        CTX.batch = 5;
-      }
       else if(!strcmp(argv[i] + 1, "refine")) {
-        CTX.batch = 6;
+        CTX.batch = 5;
         i++;
       }
       else if(!strcmp(argv[i] + 1, "part")) {
-        CTX.batch = 7;
+        CTX.batch_after_mesh = 1;
+        i++;
+      }
+      else if(!strcmp(argv[i] + 1, "new")) {
+        CTX.files.push_back("-new");
         i++;
       }
       else if(!strcmp(argv[i] + 1, "pid")) {
diff --git a/Common/Context.h b/Common/Context.h
index 2a8af88c0610d74f4b2760e2bebea44353a595b4..b9b71aa800ce19fed4d5170ac55a3d76be307914 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -64,8 +64,9 @@ class Context_T {
   int field_size[2]; // size of the field window on the screen
   int file_chooser_position[2]; // position of the file chooser window on the screen
   int system_menu_bar; // use the system menu bar on MacOS?
-  int batch; // 0=full gfx; -1=write geo; -2=check coherence; 1,2,3=batch mesh; 
-             // 4=adapt; 5=server daemon; 6=refine; 7=partition
+  int batch; // -3=server daemon; -2=check coherence; -1=write geo; 0=full gfx;
+             // 1=1D mesh; 2=2D mesh; 3=3D mesh; 4=adapt mesh; 5=refine mesh;
+  int batch_after_mesh; // 1=partition mesh
   int initial_context; // 0=automatic; 1=geom; 2=mesh; 3=solver; 4=post 
   int nopopup; // never popup dialogs in scripts (use default values instead)
   int non_modal_windows; // make all windows "non modal"
diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp
index 20352339973340abed41e7bee833eba995fd6987..83c11bf6cc2722a405f29daa89ec04e378281a29 100644
--- a/Common/Gmsh.cpp
+++ b/Common/Gmsh.cpp
@@ -101,24 +101,28 @@ int GmshBatch()
   }
 #endif
 
-  if(CTX.batch == 5)
+  if(CTX.batch == -3){
     GmshDaemon(CTX.solver.socket_name);
-  else if(CTX.batch == 4) {
-    AdaptMesh(GModel::current());
-    CreateOutputFile(CTX.output_filename, CTX.mesh.format);
   }
-  else if(CTX.batch > 0) {
-    GModel::current()->mesh(CTX.batch);
+  else if(CTX.batch == -2){
+    GModel::current()->checkMeshCoherence(CTX.geom.tolerance);
+  }
+  else if(CTX.batch == -1){
+    CreateOutputFile(CTX.output_filename, FORMAT_GEO);
+  }
+  else if(CTX.batch > 0){
+    if(CTX.batch < 4)
+      GModel::current()->mesh(CTX.batch);
+    else if(CTX.batch == 4)
+      AdaptMesh(GModel::current());
+    else if(CTX.batch == 5)
+      RefineMesh(GModel::current());
 #if defined(HAVE_CHACO) || defined(HAVE_METIS)
-    if(CTX.batch == 7)
+    if(CTX.batch_after_mesh == 1)
       PartitionMesh(GModel::current(), CTX.mesh.partition_options);
 #endif
     CreateOutputFile(CTX.output_filename, CTX.mesh.format);
   }
-  else if(CTX.batch == -1)
-    CreateOutputFile(CTX.output_filename, FORMAT_GEO);
-  else if(CTX.batch == -2)
-    GModel::current()->checkMeshCoherence(CTX.geom.tolerance);
 
   return 1;
 }
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 069c909f1e7dcd239e17b6a62fa8cad67fdb42e3..ccf8dbb8a1ce56482cf1b1a8a008004f628a299b 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -456,7 +456,7 @@ void Init_Options(int num)
   Init_Options_Safe(num);
 
   // The following defaults cannot be set by the user 
-  CTX.batch = 0;
+  CTX.batch = CTX.batch_after_mesh = 0;
   CTX.output_filename = NULL;
   CTX.bgm_filename = NULL;
   CTX.lc = 1.0;
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 722009cf3750ca18191edb20490b73b4b535c1ef..858e64c002be42dfe176c84e3a49614e53c64956 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -3830,10 +3830,10 @@ void mesh_optimize_cb(CALLBACK_ARGS)
 
 void mesh_refine_cb(CALLBACK_ARGS)
 {
-	Refine(GModel::current(), CTX.mesh.second_order_linear);
-	CTX.mesh.changed |= (ENT_LINE | ENT_SURFACE | ENT_VOLUME);
-	Draw();
-	Msg::StatusBar(2, false, " ");
+  RefineMesh(GModel::current(), CTX.mesh.second_order_linear);
+  CTX.mesh.changed |= (ENT_LINE | ENT_SURFACE | ENT_VOLUME);
+  Draw();
+  Msg::StatusBar(2, false, " ");
 }
 
 void mesh_optimize_netgen_cb(CALLBACK_ARGS)
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index 8e7f76653583849ca630f12551ed4304462d0c2e..fa715c6135872ce03f9facaed4651a6ca411e7c1 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -315,7 +315,7 @@ Context_Item menu_mesh[] = {
 #if defined(HAVE_FOURIER_MODEL)
   {"Reparameterize",   (Fl_Callback *)mesh_parameterize_cb} , 
 #endif
-  {"Reclassify",   (Fl_Callback *)mesh_classify_cb} , 
+  //  {"Reclassify",   (Fl_Callback *)mesh_classify_cb} , 
   {"Save",         (Fl_Callback *)mesh_save_cb} ,
   {0} 
 };  
diff --git a/Mesh/Generator.h b/Mesh/Generator.h
index bef74f51ad754824e39c1a7331a262ed2c754eb8..182b7032d88ea6d88ebffd5ea465ccd6d25d1060 100644
--- a/Mesh/Generator.h
+++ b/Mesh/Generator.h
@@ -13,5 +13,6 @@ void AdaptMesh(GModel *m);
 void GenerateMesh(GModel *m, int dimension);
 void OptimizeMesh(GModel *m);
 void OptimizeMeshNetgen(GModel *m);
+void RefineMesh(GModel *m, bool linear=true);
 
 #endif
diff --git a/Mesh/HighOrder.h b/Mesh/HighOrder.h
index 54a9592f19bbd1945f6005d1c00be2bc6877d999..9bd6778804abd520a607135ff61fdf8ba783f301 100644
--- a/Mesh/HighOrder.h
+++ b/Mesh/HighOrder.h
@@ -22,6 +22,5 @@ typedef std::map<MFace, std::vector<MVertex*>, Less_Face> faceContainer;
 
 void SetOrder1(GModel *m);
 void SetOrderN(GModel *m, int order, bool linear=true, bool incomplete=false);
-void Refine(GModel *m, bool linear=true);
 
 #endif
diff --git a/Mesh/Refine.cpp b/Mesh/Refine.cpp
index 54228cea61d1d917ad1f0dac16bd452ecc577864..23cca401aaa386130a5ad0d310e260205dfc17a6 100644
--- a/Mesh/Refine.cpp
+++ b/Mesh/Refine.cpp
@@ -214,7 +214,7 @@ static void Subdivide(GRegion *gr)
   gr->deleteVertexArrays();
 }
 
-void Refine(GModel *m, bool linear)
+void RefineMesh(GModel *m, bool linear)
 {
   Msg::StatusBar(1, true, "Generating refined mesh ...");
   double t1 = Cpu();
diff --git a/Numeric/Makefile b/Numeric/Makefile
index d7feb8c59c926bc34a02b3d757755df0ba4f8f61..bf6789622b9d682a2f8e5994984a43d509a1ba12 100644
--- a/Numeric/Makefile
+++ b/Numeric/Makefile
@@ -56,10 +56,9 @@ NumericEmbedded.o: NumericEmbedded.cpp NumericEmbedded.h \
   ../Common/GmshMessage.h
 gmshAssembler.o: gmshAssembler.cpp ../Geo/MVertex.h ../Geo/SPoint2.h \
   ../Geo/SPoint3.h gmshAssembler.h gmshLinearSystem.h
-gmshTermOfFormulation.o: gmshTermOfFormulation.cpp \
-  gmshTermOfFormulation.h ../Common/GmshMatrix.h gmshFunction.h \
-  ../Common/Gmsh.h ../Common/GmshMessage.h ../Geo/GModel.h \
-  ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
+gmshTermOfFormulation.o: gmshTermOfFormulation.cpp ../Common/Gmsh.h \
+  ../Common/GmshMessage.h ../Geo/GModel.h ../Geo/GVertex.h \
+  ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
   ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Geo/GPoint.h \
   ../Geo/SPoint2.h ../Geo/GEdge.h ../Geo/GEntity.h ../Geo/GVertex.h \
   ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint3.h ../Geo/SPoint2.h \
@@ -69,7 +68,8 @@ gmshTermOfFormulation.o: gmshTermOfFormulation.cpp \
   ../Geo/SBoundingBox3d.h ../Geo/MElement.h ../Common/GmshDefines.h \
   ../Geo/MVertex.h ../Geo/SPoint2.h ../Geo/SPoint3.h ../Geo/MEdge.h \
   ../Geo/MVertex.h ../Geo/SVector3.h ../Geo/MFace.h ../Geo/MVertex.h \
-  ../Geo/SVector3.h ../Numeric/FunctionSpace.h gmshLinearSystem.h \
+  ../Geo/SVector3.h ../Numeric/FunctionSpace.h ../Common/GmshMatrix.h \
+  gmshTermOfFormulation.h gmshFunction.h gmshLinearSystem.h \
   gmshAssembler.h
 gmshLaplace.o: gmshLaplace.cpp gmshLaplace.h gmshTermOfFormulation.h \
   ../Common/GmshMatrix.h ../Common/Gmsh.h ../Common/GmshMessage.h \