Index: /issm/trunk/src/c/objects/Elements/Penta.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 5858)
+++ /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 5859)
@@ -714,8 +714,12 @@
 			break;
 		case BalancedthicknessAnalysisEnum:
-			CreateKMatrixBalancedthickness( Kgg);
+			Ke=CreateKMatrixBalancedthickness();
+			if(Ke) Ke->AddToGlobal(Kgg,NULL,NULL);
+			delete Ke;
 			break;
 		case BalancedvelocitiesAnalysisEnum:
-			CreateKMatrixBalancedvelocities( Kgg);
+			Ke=CreateKMatrixBalancedvelocities();
+			if(Ke) Ke->AddToGlobal(Kgg,NULL,NULL);
+			delete Ke;
 			break;
 		case ThermalAnalysisEnum:
@@ -1944,14 +1948,10 @@
 /*}}}*/
 /*FUNCTION Penta::CreateKMatrixBalancedthickness {{{1*/
-void  Penta::CreateKMatrixBalancedthickness(Mat Kgg){
-
-	/*Collapsed formulation: */
-	Tria*  tria=NULL;
-
-	/*If on water, skip: */
-	if(IsOnWater())return;
-
-	/*Is this element on the bed? :*/
-	if(!IsOnBed())return;
+ElementMatrix* Penta::CreateKMatrixBalancedthickness(void){
+
+	/*Figure out if this penta is collapsed. If so, then bailout, except if it is at the 
+	  bedrock, in which case we spawn a tria element using the 3 first grids, and use it to build 
+	  the stiffness matrix. */
+	if (!IsOnBed() || IsOnWater()) return NULL;
 
 	/*Depth Averaging Vx and Vy*/
@@ -1960,6 +1960,6 @@
 
 	/*Spawn Tria element from the base of the Penta: */
-	tria=(Tria*)SpawnTria(0,1,2); //grids 0, 1 and 2 make the new tria.
-	tria->CreateKMatrix(Kgg,NULL,NULL);
+	Tria* tria=(Tria*)SpawnTria(0,1,2); //grids 0, 1 and 2 make the new tria.
+	ElementMatrix* Ke=tria->CreateKMatrixBalancedthickness();
 	delete tria->matice; delete tria;
 
@@ -1968,20 +1968,15 @@
 	this->inputs->DeleteInput(VyAverageEnum);
 
-	return;
-
+	/*clean up and return*/
+	return Ke;
 }
 /*}}}*/
 /*FUNCTION Penta::CreateKMatrixBalancedvelocities {{{1*/
-
-void  Penta::CreateKMatrixBalancedvelocities(Mat Kgg){
-
-	/*Collapsed formulation: */
-	Tria*  tria=NULL;
-
-	/*If on water, skip: */
-	if(IsOnWater())return;
-
-	/*Is this element on the bed? :*/
-	if(!IsOnBed())return;
+ElementMatrix* Penta::CreateKMatrixBalancedvelocities(void){
+
+	/*Figure out if this penta is collapsed. If so, then bailout, except if it is at the 
+	  bedrock, in which case we spawn a tria element using the 3 first grids, and use it to build 
+	  the stiffness matrix. */
+	if (!IsOnBed() || IsOnWater()) return NULL;
 
 	/*Depth Averaging Vx and Vy*/
@@ -1990,6 +1985,6 @@
 
 	/*Spawn Tria element from the base of the Penta: */
-	tria=(Tria*)SpawnTria(0,1,2); //grids 0, 1 and 2 make the new tria.
-	tria->CreateKMatrix(Kgg,NULL,NULL);
+	Tria* tria=(Tria*)SpawnTria(0,1,2); //grids 0, 1 and 2 make the new tria.
+	ElementMatrix* Ke=tria->CreateKMatrixBalancedvelocities();
 	delete tria->matice; delete tria;
 
@@ -1998,6 +1993,6 @@
 	this->inputs->DeleteInput(VyAverageEnum);
 
-	return;
-
+	/*clean up and return*/
+	return Ke;
 }
 /*}}}*/
Index: /issm/trunk/src/c/objects/Elements/Penta.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.h	(revision 5858)
+++ /issm/trunk/src/c/objects/Elements/Penta.h	(revision 5859)
@@ -121,6 +121,6 @@
 		/*Penta specific routines:{{{1*/
 		void	  BedNormal(double* bed_normal, double xyz_list[3][3]);
-		void	  CreateKMatrixBalancedthickness(Mat Kggg);
-		void	  CreateKMatrixBalancedvelocities(Mat Kggg);
+		ElementMatrix* CreateKMatrixBalancedthickness(void);
+		ElementMatrix* CreateKMatrixBalancedvelocities(void);
 		void	  CreateKMatrixCouplingMacAyealPattyn( Mat Kgg);
 		void	  CreateKMatrixCouplingMacAyealPattynViscous( Mat Kgg);
