Index: issm/trunk/src/c/DataSet/DataSet.cpp
===================================================================
--- issm/trunk/src/c/DataSet/DataSet.cpp	(revision 3966)
+++ issm/trunk/src/c/DataSet/DataSet.cpp	(revision 3967)
@@ -577,27 +577,4 @@
 }
 /*}}}*/
-/*FUNCTION DataSet::CostFunction{{{1*/
-void  DataSet::CostFunction(double* pJ,int analysis_type,int sub_analysis_type){
-
-	double J=0;;
-
-	vector<Object*>::iterator object;
-	Element* element=NULL;
-
-	for ( object=objects.begin() ; object < objects.end(); object++ ){
-
-		if(EnumIsElement((*object)->Enum())){
-
-			element=(Element*)(*object);
-			J+=element->CostFunction(analysis_type,sub_analysis_type);
-
-		}
-	}
-
-	/*Assign output pointers:*/
-	*pJ=J;
-
-}
-/*}}}*/
 /*FUNCTION DataSet::CreatePartitioningVector{{{1*/
 void  DataSet::CreatePartitioningVector(Vec* ppartition,int numberofobjects){
@@ -707,23 +684,4 @@
 	xfree((void**)&truedofs);
 	xfree((void**)&alltruedofs);
-
-}
-/*}}}*/
-/*FUNCTION DataSet::Du{{{1*/
-void  DataSet::Du(Vec du_g,int analysis_type,int sub_analysis_type){
-
-
-	vector<Object*>::iterator object;
-	Element* element=NULL;
-
-	for ( object=objects.begin() ; object < objects.end(); object++ ){
-
-		if(EnumIsElement((*object)->Enum())){
-
-			element=(Element*)(*object);
-			element->Du(du_g,analysis_type,sub_analysis_type);
-		}
-	}
-
 
 }
@@ -966,23 +924,4 @@
 }
 /*}}}*/
-/*FUNCTION DataSet::Gradj{{{1*/
-void  DataSet::Gradj(Vec grad_g,int analysis_type,int sub_analysis_type,int control_type){
-
-
-	vector<Object*>::iterator object;
-	Element* element=NULL;
-
-	for ( object=objects.begin() ; object < objects.end(); object++ ){
-
-		if(EnumIsElement((*object)->Enum())){
-
-			element=(Element*)(*object);
-			element->Gradj(grad_g,analysis_type,sub_analysis_type,control_type);
-		}
-	}
-
-
-}		
-/*}}}*/
 /*FUNCTION DataSet::MeltingIsPresent{{{1*/
 int   DataSet::MeltingIsPresent(){
@@ -1050,27 +989,4 @@
 	*pconverged=converged;
 	*pnum_unstable_constraints=num_unstable_constraints;
-}
-/*}}}*/
-/*FUNCTION DataSet::Misfit{{{1*/
-void  DataSet::Misfit(double* pJ,int analysis_type,int sub_analysis_type){
-
-	double J=0;;
-
-	vector<Object*>::iterator object;
-	Element* element=NULL;
-
-	for ( object=objects.begin() ; object < objects.end(); object++ ){
-
-		if(EnumIsElement((*object)->Enum())){
-
-			element=(Element*)(*object);
-			J+=element->Misfit(analysis_type,sub_analysis_type);
-
-		}
-	}
-
-	/*Assign output pointers:*/
-	*pJ=J;
-
 }
 /*}}}*/
Index: issm/trunk/src/c/DataSet/DataSet.h
===================================================================
--- issm/trunk/src/c/DataSet/DataSet.h	(revision 3966)
+++ issm/trunk/src/c/DataSet/DataSet.h	(revision 3967)
@@ -81,8 +81,4 @@
 		void  MeltingConstraints(int* pconverged, int* pnum_unstable_constraints,int analysis_type,int sub_analysis_type);
 		DataSet* Copy(void);
-		void  Du(Vec du_g,int analysis_type,int sub_analysis_type);
-		void  Gradj(Vec grad_g,int analysis_type,int sub_analysis_type,int control_type);
-		void  Misfit(double* pJ, int analysis_type,int sub_analysis_type);
-		void  CostFunction(double* pJ, int analysis_type,int sub_analysis_type);
 		void  SurfaceArea(double* pS, int analysis_type,int sub_analysis_type);
 		void  FieldAverageOntoVertices(Vec fieldsum,Vec connectivity,double* field);
Index: issm/trunk/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.cpp
===================================================================
--- issm/trunk/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.cpp	(revision 3966)
+++ issm/trunk/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.cpp	(revision 3967)
@@ -12,17 +12,28 @@
 int	ConfigureObjectsx( DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials,Parameters* parameters){
 
+	/*Intermediary*/
 	int noerr=1;
 	int i;
-
-	extern int num_procs;
-	extern int my_rank;
+	Element* element=NULL;
+	Load* load=NULL;
+	Node* node=NULL;
 	
 	//_printf_("      Configuring elements...\n");
-	elements->Configure(elements,loads,nodes,vertices,materials,parameters);
+	for (i=0;i<elements->Size();i++){
+		element=(Element*)elements->GetObjectByOffset(i);
+		element->Configure(elements,loads,nodes,materials,parameters);
+	}
 	//_printf_("      Configuring loads...\n");
-	loads->Configure(elements,loads,nodes,vertices,materials,parameters);
+	for (i=0;i<loads->Size();i++){
+		load=(Load*)loads->GetObjectByOffset(i);
+		load->Configure(elements,loads,nodes,vertices,materials,parameters);
+	}
 	//_printf_("      Configuring nodes...\n");
-	nodes->Configure(elements,loads,nodes,vertices,materials,parameters);
+	for (i=0;i<nodes->Size();i++){
+		node=(Node*)nodes->GetObjectByOffset(i);
+		node->Configure(nodes,vertices);
+	}
 	//_printf_("      Configuring parameters...\n");
+	/*parameters ARE NOT configured!*/
 	parameters->Configure(elements,loads,nodes,vertices,materials,parameters);
 
Index: issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.cpp
===================================================================
--- issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.cpp	(revision 3966)
+++ issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.cpp	(revision 3967)
@@ -15,9 +15,11 @@
 
 	/*Intermediary*/
+	int    i;
 	double fit;
 	double S;
+	Element* element=NULL;
 
 	/*output: */
-	double J;
+	double J=0;
 	double J_sum;
 	
@@ -33,6 +35,9 @@
 	elements->UpdateInputsFromVector(&S,SurfaceAreaEnum,ConstantEnum);
 	
-	/*Compute gradients: */
-	elements->CostFunction(&J,analysis_type,sub_analysis_type);
+	/*Compute cost function: */
+	for (i=0;i<elements->Size();i++){
+		element=(Element*)elements->GetObjectByOffset(i);
+		J+=element->CostFunction(analysis_type,sub_analysis_type);
+	}
 
 	/*Sum all J from all cpus of the cluster:*/
Index: issm/trunk/src/c/modules/Dofx/Dofx.cpp
===================================================================
--- issm/trunk/src/c/modules/Dofx/Dofx.cpp	(revision 3966)
+++ issm/trunk/src/c/modules/Dofx/Dofx.cpp	(revision 3967)
@@ -32,5 +32,5 @@
 
 	/*Initialize dofvecs: */
-	partition=new DofVec("partition");
+	partition=new  DofVec("partition");
 	tpartition=new DofVec("tpartition");
 
Index: issm/trunk/src/c/modules/Dux/Dux.cpp
===================================================================
--- issm/trunk/src/c/modules/Dux/Dux.cpp	(revision 3966)
+++ issm/trunk/src/c/modules/Dux/Dux.cpp	(revision 3967)
@@ -20,4 +20,5 @@
 	double fit=-1;
 	double S;
+	Element* element=NULL;
 
 	/*output: */
@@ -25,6 +26,6 @@
 
 	/*First, get elements and loads configured: */
-	elements->Configure(elements,loads, nodes, vertices, materials,parameters);
-	nodes->Configure(elements,loads, nodes, vertices, materials,parameters);
+	elements->  Configure(elements,loads, nodes, vertices, materials,parameters);
+	nodes->     Configure(elements,loads, nodes, vertices, materials,parameters);
 	parameters->Configure(elements,loads, nodes, vertices, materials,parameters);
 
@@ -42,5 +43,8 @@
 
 	/*Compute velocity difference: */
-	elements->Du(du_g,analysis_type,sub_analysis_type);
+	for (i=0;i<elements->Size();i++){
+		element=(Element*)elements->GetObjectByOffset(i);
+		element->Du(du_g,analysis_type,sub_analysis_type);
+	}
 
 	/*Assemble vector: */
Index: issm/trunk/src/c/modules/Gradjx/Gradjx.cpp
===================================================================
--- issm/trunk/src/c/modules/Gradjx/Gradjx.cpp	(revision 3966)
+++ issm/trunk/src/c/modules/Gradjx/Gradjx.cpp	(revision 3967)
@@ -13,10 +13,14 @@
 			int analysis_type,int sub_analysis_type,int control_type){
 
+	/*Intermediary*/
+	int i;
+	Element* element=NULL;
+
 	/*output: */
 	Vec grad_g=NULL;
 
 	/*First, get elements and loads configured: */
-	elements->Configure(elements,loads, nodes,vertices, materials,parameters);
-	nodes->Configure(elements,loads, nodes,vertices, materials,parameters);
+	elements->  Configure(elements,loads, nodes,vertices, materials,parameters);
+	nodes->     Configure(elements,loads, nodes,vertices, materials,parameters);
 	parameters->Configure(elements,loads, nodes,vertices, materials,parameters);
 
@@ -25,5 +29,8 @@
 
 	/*Compute gradients: */
-	elements->Gradj(grad_g,analysis_type,sub_analysis_type,control_type);
+	for (i=0;i<elements->Size();i++){
+		element=(Element*)elements->GetObjectByOffset(i);
+		element->Gradj(grad_g,analysis_type,sub_analysis_type,control_type);
+	}
 
 	/*Assemble vector: */
Index: issm/trunk/src/c/modules/Misfitx/Misfitx.cpp
===================================================================
--- issm/trunk/src/c/modules/Misfitx/Misfitx.cpp	(revision 3966)
+++ issm/trunk/src/c/modules/Misfitx/Misfitx.cpp	(revision 3967)
@@ -17,7 +17,9 @@
 	int fit;
 	double S;
+	int i;
+	Element* element=NULL;
 
 	/*output: */
-	double J;
+	double J=0;
 	double J_sum;
 	
@@ -32,8 +34,10 @@
 	/*add surface area to elements :*/
 	elements->UpdateInputsFromVector(&S,SurfaceAreaEnum,ConstantEnum);
-	
 
 	/*Compute Misfit: */
-	elements->Misfit(&J,analysis_type,sub_analysis_type);
+	for (i=0;i<elements->Size();i++){
+		element=(Element*)elements->GetObjectByOffset(i);
+		J+=element->Misfit(analysis_type,sub_analysis_type);
+	}
 
 	/*Sum all J from all cpus of the cluster:*/
