Index: Singular/iparith.cc
===================================================================
--- Singular/iparith.cc	(revision 8f40312428677d88ab37a31824f2ec53f144a18a)
+++ Singular/iparith.cc	(revision ebdaa15ecbc43fde002acee364368cebc63dd911)
@@ -3783,8 +3783,8 @@
 {
   lists L=(lists)omAllocBin(slists_bin);
-  if (rField_is_Zp()
-  || rField_is_Q()
-  || rField_is_Zp_a()
-  || rField_is_Q_a())
+  if (rField_is_Zp(currRing)
+  || rField_is_Q(currRing)
+  || rField_is_Zp_a(currRing)
+  || rField_is_Q_a(currRing))
   {
     ideal_list p,h;
Index: libpolys/coeffs/modulop.cc
===================================================================
--- libpolys/coeffs/modulop.cc	(revision 8f40312428677d88ab37a31824f2ec53f144a18a)
+++ libpolys/coeffs/modulop.cc	(revision ebdaa15ecbc43fde002acee364368cebc63dd911)
@@ -316,8 +316,8 @@
       ii *= 10;
       ii += *s++ - '0';
-      if (ii >= (MAX_INT / 10)) ii = ii % r->npPrimeM;
+      if (ii >= (MAX_INT_VAL / 10)) ii = ii % r->npPrimeM;
     }
     while (((*s) >= '0') && ((*s) <= '9'));
-    if (ii >= npPrimeM) ii = ii % r->npPrimeM;
+    if (ii >= r->npPrimeM) ii = ii % r->npPrimeM;
     *i=(int)ii;
   }
Index: libpolys/coeffs/numbers.cc
===================================================================
--- libpolys/coeffs/numbers.cc	(revision 8f40312428677d88ab37a31824f2ec53f144a18a)
+++ libpolys/coeffs/numbers.cc	(revision ebdaa15ecbc43fde002acee364368cebc63dd911)
@@ -358,5 +358,4 @@
         WarnS("cf_root list destroyed");
       }
-      r->cf=NULL;
     }
   }
Index: libpolys/polys/sparsmat.cc
===================================================================
--- libpolys/polys/sparsmat.cc	(revision 8f40312428677d88ab37a31824f2ec53f144a18a)
+++ libpolys/polys/sparsmat.cc	(revision ebdaa15ecbc43fde002acee364368cebc63dd911)
@@ -60,23 +60,22 @@
 
 
+/* declare internal 'C' stuff */
+static void sm_ExactPolyDiv(poly, poly, const ring);
+static BOOLEAN sm_IsNegQuot(poly, const poly, const poly, const ring);
+static void sm_ExpMultDiv(poly, const poly, const poly, const ring);
+static void sm_PolyDivN(poly, const number, const ring);
+static BOOLEAN smSmaller(poly, poly);
+static void sm_CombineChain(poly *, poly, const ring);
+static void sm_FindRef(poly *, poly *, poly, const ring);
+
+static void sm_ElemDelete(smpoly *, const ring);
+static smpoly smElemCopy(smpoly);
+static float sm_PolyWeight(smpoly, const ring);
+static smpoly sm_Poly2Smpoly(poly, const ring);
+static poly sm_Smpoly2Poly(smpoly, const ring);
+static BOOLEAN sm_HaveDenom(poly, const ring);
+static number sm_Cleardenom(ideal, const ring);
+
 omBin smprec_bin = omGetSpecBin(sizeof(smprec));
-
-static void smExpMultDiv(poly t, const poly b, const poly c)
-{
-  int i;
-  pTest(t);
-  pLmTest(b);
-  pLmTest(c);
-  poly bc = p_New(currRing);
-
-  p_ExpVectorDiff(bc, b, c, currRing);
-
-  while(t!=NULL)
-  {
-    pExpVectorAdd(t, bc);
-    pIter(t);
-  }
-  p_LmFree(bc, currRing);
-}
 
 static poly pp_Mult_Coeff_mm_DivSelect_MultDiv(poly p, int &lp, poly m,
@@ -353,54 +352,4 @@
 
 /* ----------------- basics (used from 'C') ------------------ */
-static BOOLEAN smHaveDenom(poly a)
-{
-  BOOLEAN sw;
-  number x;
-
-  while (a != NULL)
-  {
-    x = nGetDenom(pGetCoeff(a));
-    sw = nIsOne(x);
-    nDelete(&x);
-    if (!sw)
-    {
-      return TRUE;
-    }
-    pIter(a);
-  }
-  return FALSE;
-}
-
-static number smCleardenom(ideal id)
-{
-  poly a;
-  number x,y,res=nInit(1);
-  BOOLEAN sw=FALSE;
-
-  for (int i=0; i<IDELEMS(id); i++)
-  {
-    a = id->m[i];
-    sw = smHaveDenom(a);
-    if (sw) break;
-  }
-  if (!sw) return res;
-  for (int i=0; i<IDELEMS(id); i++)
-  {
-    a = id->m[i];
-    if (a!=NULL)
-    {
-      x = nCopy(pGetCoeff(a));
-      p_Cleardenom(a, currRing);
-      y = nDiv(x,pGetCoeff(a));
-      nDelete(&x);
-      x = nMult(res,y);
-      nNormalize(x);
-      nDelete(&res);
-      res = x;
-    }
-  }
-  return res;
-}
-
 /*2
 *returns the determinant of the module I;
@@ -486,41 +435,4 @@
   sm_KillModifiedRing(tmpR);
   M=II;
-}
-
-/*
-* from poly to smpoly
-* do not destroy p
-*/
-static smpoly smPoly2Smpoly(poly q)
-{
-  poly pp;
-  smpoly res, a;
-  long x;
-
-  if (q == NULL)
-    return NULL;
-  a = res = (smpoly)omAllocBin(smprec_bin);
-  a->pos = x = pGetComp(q);
-  a->m = q;
-  a->e = 0;
-  loop
-  {
-    pSetComp(q,0);
-    pp = q;
-    pIter(q);
-    if (q == NULL)
-    {
-      a->n = NULL;
-      return res;
-    }
-    if (pGetComp(q) != x)
-    {
-      a = a->n = (smpoly)omAllocBin(smprec_bin);
-      pNext(pp) = NULL;
-      a->pos = x = pGetComp(q);
-      a->m = q;
-      a->e = 0;
-    }
-  }
 }
 
@@ -587,46 +499,4 @@
 
 /*
-* from smpoly to poly
-* destroy a
-*/
-static poly smSmpoly2Poly(smpoly a)
-{
-  smpoly b;
-  poly res, pp, q;
-  long x;
-
-  if (a == NULL)
-    return NULL;
-  x = a->pos;
-  q = res = a->m;
-  loop
-  {
-    pSetComp(q,x);
-    pp = q;
-    pIter(q);
-    if (q == NULL)
-      break;
-  }
-  loop
-  {
-    b = a;
-    a = a->n;
-    omFreeBin((void *)b,  smprec_bin);
-    if (a == NULL)
-      return res;
-    x = a->pos;
-    q = pNext(pp) = a->m;
-    loop
-    {
-      pSetComp(q,x);
-      pp = q;
-      pIter(q);
-      if (q == NULL)
-        break;
-    }
-  }
-}
-
-/*
 * transform the result to a module
 */
@@ -789,36 +659,4 @@
 
 /*
-* weigth of a polynomial, for pivot strategy
-*/
-static float smPolyWeight(smpoly a)
-{
-  poly p = a->m;
-  int i;
-  float res = (float)nSize(pGetCoeff(p));
-
-  if (pNext(p) == NULL)
-  {
-    for(i=pVariables; i>0; i--)
-    {
-      if (pGetExp(p,i) != 0) return res+1.0;
-    }
-    return res;
-  }
-  else
-  {
-    i = 0;
-    res = 0.0;
-    do
-    {
-      i++;
-      res += (float)nSize(pGetCoeff(p));
-      pIter(p);
-    }
-    while (p);
-    return res+(float)i;
-  }
-}
-
-/*
 * prepare smPivot, compute weights for rows and columns
 * and the weight for all points
@@ -1011,20 +849,4 @@
 
 /* ----------------- elimination ------------------ */
-static void smElemDelete(smpoly *r)
-{
-  smpoly a = *r, b = a->n;
-
-  pDelete(&a->m);
-  omFreeBin((void *)a,  smprec_bin);
-  *r = b;
-}
-
-static smpoly smElemCopy(smpoly a)
-{
-  smpoly r = (smpoly)omAllocBin(smprec_bin);
-  memcpy(r, a, sizeof(smprec));
-/*  r->m = pCopy(r->m); */
-  return r;
-}
 
 /* first step of elimination */
@@ -1843,140 +1665,4 @@
 
 
-static BOOLEAN smIsNegQuot(poly a, const poly b, const poly c)
-{
-  if (pLmDivisibleByNoComp(c, b))
-  {
-    pExpVectorDiff(a, b, c);
-    // Hmm: here used to be a pSetm(a): but it is unnecessary,
-    // if b and c are correct
-    return FALSE;
-  }
-  else
-  {
-    int i;
-    for (i=pVariables; i>0; i--)
-    {
-      if(pGetExp(c,i) > pGetExp(b,i))
-        pSetExp(a,i,pGetExp(c,i)-pGetExp(b,i));
-      else
-        pSetExp(a,i,0);
-    }
-    // here we actually might need a pSetm, if a is to be used in
-    // comparisons
-    return TRUE;
-  }
-}
-
-static BOOLEAN smSmaller(poly a, poly b)
-{
-  loop
-  {
-    pIter(b);
-    if (b == NULL) return TRUE;
-    pIter(a);
-    if (a == NULL) return FALSE;
-  }
-}
-
-static void smCombineChain(poly *px, poly r)
-{
-  poly pa = *px, pb;
-  number x;
-  int i;
-
-  loop
-  {
-    pb = pNext(pa);
-    if (pb == NULL)
-    {
-      pa = pNext(pa) = r;
-      break;
-    }
-    i = pLmCmp(pb, r);
-    if (i > 0)
-      pa = pb;
-    else
-    {
-      if (i == 0)
-      {
-        x = nAdd(pGetCoeff(pb), pGetCoeff(r));
-        pLmDelete(&r);
-        if (nIsZero(x))
-        {
-          pLmDelete(&pb);
-          pNext(pa) = pAdd(pb,r);
-        }
-        else
-        {
-          pa = pb;
-          pSetCoeff(pa,x);
-          pNext(pa) = pAdd(pNext(pa), r);
-        }
-      }
-      else
-      {
-        pa = pNext(pa) = r;
-        pNext(pa) = pAdd(pb, pNext(pa));
-      }
-      break;
-    }
-  }
-  *px = pa;
-}
-
-static void smFindRef(poly *ref, poly *px, poly r)
-{
-  number x;
-  int i;
-  poly pa = *px, pp = NULL;
-
-  loop
-  {
-    i = pLmCmp(pa, r);
-    if (i > 0)
-    {
-      pp = pa;
-      pIter(pa);
-      if (pa==NULL)
-      {
-        pNext(pp) = r;
-        break;
-      }
-    }
-    else
-    {
-      if (i == 0)
-      {
-        x = nAdd(pGetCoeff(pa), pGetCoeff(r));
-        pLmDelete(&r);
-        if (nIsZero(x))
-        {
-          pLmDelete(&pa);
-          if (pp!=NULL)
-            pNext(pp) = pAdd(pa,r);
-          else
-            *px = pAdd(pa,r);
-        }
-        else
-        {
-          pp = pa;
-          pSetCoeff(pp,x);
-          pNext(pp) = pAdd(pNext(pp), r);
-        }
-      }
-      else
-      {
-        if (pp!=NULL)
-          pp = pNext(pp) = r;
-        else
-          *px = pp = r;
-        pNext(pp) = pAdd(pa, pNext(r));
-      }
-      break;
-    }
-  }
-  *ref = pp;
-}
-
 //disable that, as it fails with coef buckets
 //#define X_MAS
@@ -1994,5 +1680,5 @@
   if ((c == NULL) || pLmIsConstantComp(c))
   {
-    return ppMult_qq(a, b);
+    return pp_Mult_qq(a, b);
   }
 
@@ -2618,5 +2304,5 @@
     }
   }
-  smExactPolyDiv(a, b);
+  return res;
 }
 
