Index: libpolys/polys/matpol.cc
===================================================================
--- libpolys/polys/matpol.cc	(revision 2f5936105b139a5635034b6eb233c5405b3e3e29)
+++ libpolys/polys/matpol.cc	(revision b78996bd38738803463c728c870213d161a8a4fe)
@@ -30,5 +30,4 @@
 #include "monomials/ring.h"
 #include "monomials/p_polys.h"
-// #include <kernel/sparsmat.h>
 
 #include "coeffrings.h"
@@ -365,5 +364,5 @@
   int       *qrow, *qcol;
   poly      *Xarray;
-  ring      _R;
+  const ring      _R;
   
   void mpInitMat();
@@ -1094,8 +1093,8 @@
         if (ap[jj] != NULL)
         {
-          q2 = SM_MULT(ap[jj], elim, div);
+          q2 = SM_MULT(ap[jj], elim, div, _R);
           if (a[jj] != NULL)
           {
-            q1 = SM_MULT(a[jj], piv, div);
+            q1 = SM_MULT(a[jj], piv, div, _R);
             p_Delete(&a[jj], _R);
             q2 = p_Add_q(q2, q1, _R);
@@ -1104,8 +1103,8 @@
         else if (a[jj] != NULL)
         {
-          q2 = SM_MULT(a[jj], piv, div);
+          q2 = SM_MULT(a[jj], piv, div, _R);
         }
         if ((q2!=NULL) && div)
-          SM_DIV(q2, div);
+          SM_DIV(q2, div, _R);
         a[jj] = q2;
       }
@@ -1119,8 +1118,8 @@
         if (a[jj] != NULL)
         {
-          q2 = SM_MULT(a[jj], piv, div);
+          q2 = SM_MULT(a[jj], piv, div, _R);
           p_Delete(&a[jj], _R);
           if (div)
-            SM_DIV(q2, div);
+            SM_DIV(q2, div, _R);
           a[jj] = q2;
         }
@@ -1839,17 +1838,17 @@
         if (a[j] != NULL)
         {
-          q1 = SM_MULT(a[j], piv, div);
+          q1 = SM_MULT(a[j], piv, div, _R);
           if (ap[j] != NULL)
           {
-            q2 = SM_MULT(ap[j], elim, div);
+            q2 = SM_MULT(ap[j], elim, div, _R);
             q1 = p_Add_q(q1,q2, _R);
           }
         }
         else if (ap[j] != NULL)
-          q1 = SM_MULT(ap[j], elim, div);
+          q1 = SM_MULT(ap[j], elim, div, _R);
         if (q1 != NULL)
         {
           if (div)
-            SM_DIV(q1, div);
+            SM_DIV(q1, div, _R);
           q[j] = q1;
         }
@@ -1862,7 +1861,7 @@
         if (a[j] != NULL)
         {
-          q1 = SM_MULT(a[j], piv, div);
+          q1 = SM_MULT(a[j], piv, div, _R);
           if (div)
-            SM_DIV(q1, div);
+            SM_DIV(q1, div, _R);
           q[j] = q1;
         }
Index: libpolys/polys/simpleideals.h
===================================================================
--- libpolys/polys/simpleideals.h	(revision 2f5936105b139a5635034b6eb233c5405b3e3e29)
+++ libpolys/polys/simpleideals.h	(revision b78996bd38738803463c728c870213d161a8a4fe)
@@ -8,6 +8,6 @@
 * ABSTRACT - all basic methods to manipulate ideals
 */
+#include <omalloc/omalloc.h>
 #include <polys/monomials/ring.h>
-#include <omalloc/omalloc.h>
 
 struct sip_sideal
Index: libpolys/polys/sparsmat.cc
===================================================================
--- libpolys/polys/sparsmat.cc	(revision 2f5936105b139a5635034b6eb233c5405b3e3e29)
+++ libpolys/polys/sparsmat.cc	(revision b78996bd38738803463c728c870213d161a8a4fe)
@@ -8,17 +8,31 @@
 */
 
-#include <kernel/mod2.h>
-#include <kernel/options.h>
-#include <kernel/febase.h>
-#include <kernel/intvec.h>
-#include <kernel/ring.h>
-#include <kernel/polys.h>
-#include <kernel/ideals.h>
-#include <kernel/numbers.h>
-#include <kernel/sparsmat.h>
-#include <kernel/prCopy.h>
-#include <kernel/p_Procs.h>
-#include <kernel/kbuckets.h>
-#include <kernel/p_Mult_q.h>
+#include "config.h"
+#include <misc/auxiliary.h>
+
+#include <omalloc/omalloc.h>
+#include <misc/mylimits.h>
+
+#include <misc/options.h>
+
+#include <reporter/reporter.h>
+#include <misc/intvec.h>
+
+#include <coeffs/numbers.h>
+#include "coeffrings.h"
+
+#include "monomials/ring.h"
+#include "monomials/p_polys.h"
+
+#include "simpleideals.h"
+
+
+#include "sparsmat.h"
+#include "prCopy.h"
+
+#include "templates/p_Procs.h"
+
+#include "kbuckets.h"
+#include "operations/p_Mult_q.h"
 
 // define SM_NO_BUCKETS, if sparsemat stuff should not use buckets
@@ -67,5 +81,5 @@
 
 static poly pp_Mult_Coeff_mm_DivSelect_MultDiv(poly p, int &lp, poly m,
-                                               poly a, poly b)
+                                               poly a, poly b, const ring currRing)
 {
   if (rOrd_is_Comp_dp(currRing) && currRing->ExpL_Size > 2)
@@ -83,13 +97,13 @@
   {
     p = pp_Mult_Coeff_mm_DivSelect(p, lp, m, currRing);
-    smExpMultDiv(p, a, b);
+    sm_ExpMultDiv(p, a, b, currRing);
   }
   return p;
 }
 
-static poly smSelectCopy_ExpMultDiv(poly p, poly m, poly a, poly b)
+static poly sm_SelectCopy_ExpMultDiv(poly p, poly m, poly a, poly b, const ring currRing)
 {
   int lp = 0;
-  return pp_Mult_Coeff_mm_DivSelect_MultDiv(p, lp, m, a, b);
+  return pp_Mult_Coeff_mm_DivSelect_MultDiv(p, lp, m, a, b, currRing);
 }
 
@@ -133,4 +147,6 @@
   smpoly piv, oldpiv;  // pivot and previous pivot
   smpoly dumm;         // allocated dummy
+  const ring _R;
+  
   void smColToRow();
   void smRowToCol();
@@ -157,5 +173,5 @@
   void smNormalize();
 public:
-  sparse_mat(ideal);
+  sparse_mat(ideal, const ring);
   ~sparse_mat();
   int smGetSign() { return sign; }
@@ -175,5 +191,6 @@
 */
 static void smMinSelect(long *, int, int);
-long smExpBound( ideal m, int di, int ra, int t)
+
+long sm_ExpBound( ideal m, int di, int ra, int t, const ring currRing)
 {
   poly p;
@@ -193,12 +210,12 @@
     while(p!=NULL)
     {
-      k = pGetComp(p)-1;
+      k = p_GetComp(p, currRing)-1;
       kr = r[k];
-      for (j=pVariables;j>0;j--)
-      {
-        if(pGetExp(p,j)>kc)
-          kc=pGetExp(p,j);
-        if(pGetExp(p,j)>kr)
-          kr=pGetExp(p,j);
+      for (j=rVar(currRing);j>0;j--)
+      {
+        if(p_GetExp(p,j, currRing)>kc)
+          kc=p_GetExp(p,j, currRing);
+        if(p_GetExp(p,j, currRing)>kr)
+          kr=p_GetExp(p,j, currRing);
       }
       r[k] = kr;
@@ -244,7 +261,7 @@
 
 /* ----------------- ops with rings ------------------ */
-ring smRingChange(ring *origR, long bound)
-{
-  *origR =currRing;
+ring sm_RingChange(const ring currRing, long bound)
+{
+//  *origR =currRing;
   ring tmpR=rCopy0(currRing,FALSE,FALSE);
   int *ord=(int*)omAlloc0(3*sizeof(int));
@@ -268,7 +285,7 @@
   if ((*origR)->qideal!=NULL)
   {
-    tmpR->qideal= idrCopyR_NoSort((*origR)->qideal, (*origR), tmpR);
-  }
-  rChangeCurrRing(tmpR);
+    tmpR->qideal= idrCopyR_NoSort((*origR)->qideal, currRing, tmpR);
+  }
+//  rChangeCurrRing(tmpR);
   if (TEST_OPT_PROT)
     Print("[%ld:%d]", (long) tmpR->bitmask, tmpR->ExpL_Size);
@@ -276,5 +293,5 @@
 }
 
-void smKillModifiedRing(ring r)
+void sm_KillModifiedRing(ring r)
 {
   if (r->qideal!=NULL) id_Delete(&(r->qideal),r);
Index: libpolys/polys/sparsmat.h
===================================================================
--- libpolys/polys/sparsmat.h	(revision 2f5936105b139a5635034b6eb233c5405b3e3e29)
+++ libpolys/polys/sparsmat.h	(revision b78996bd38738803463c728c870213d161a8a4fe)
@@ -11,26 +11,26 @@
 
 
-poly smMult(poly, poly);
-void smPolyDiv(poly, poly);
-poly smMultDiv(poly, poly, const poly);
-void smSpecialPolyDiv(poly, poly);
+poly sm_Mult(poly, poly, const ring);
+void sm_PolyDiv(poly, poly, const ring);
+poly sm_MultDiv(poly, poly, const poly, const ring);
+void sm_SpecialPolyDiv(poly, poly, const ring);
 /* ----------------- macros ------------------ */
 /* #define OLD_DIV 1 */
 
 #ifdef OLD_DIV
-#define SM_MULT(A,B,C) smMult(A,B)
-#define SM_DIV smPolyDiv
+#define SM_MULT(A,B,C, R) sm_Mult(A,B,R)
+#define SM_DIV sm_PolyDiv
 #else
-#define SM_MULT smMultDiv
-#define SM_DIV smSpecialPolyDiv
+#define SM_MULT sm_MultDiv
+#define SM_DIV sm_SpecialPolyDiv
 #endif
 
-poly smCallDet(ideal I);
-void smCallBareiss(ideal smat, int x, int y, ideal & M, intvec ** iv);
-ideal smCallSolv(ideal I);
+poly sm_CallDet(ideal I, const ring);
+void sm_CallBareiss(ideal smat, int x, int y, ideal & M, intvec ** iv, const ring);
+ideal sm_CallSolv(ideal I, const ring);
 
-ring smRingChange(ring *, long);
-void smKillModifiedRing(ring r);
-long smExpBound(ideal, int, int, int);
-BOOLEAN smCheckDet(ideal, int, BOOLEAN);
+ring sm_RingChange(const ring, long);
+void sm_KillModifiedRing(ring r);
+long sm_ExpBound(ideal, int, int, int, const ring);
+BOOLEAN sm_CheckDet(ideal, int, BOOLEAN, const ring);
 #endif
