diff --git a/compileTimeOptions.h b/compileTimeOptions.h
index 32422afb17b9d6fbf2facaefd0f6fb1b20ac74a7..865d26f9eca3f95bbd7cccfba52ab4192f453a4a 100644
--- a/compileTimeOptions.h
+++ b/compileTimeOptions.h
@@ -32,6 +32,15 @@
 #endif
 
 
+#ifndef USE_NEXT_FORB
+#define USE_NEXT_FORB 1
+#endif
+#if USE_NEXT_FORB
+#pragma message "USE_NEXT_FORB ON"
+#else
+#pragma message "USE_NEXT_FORB off"
+#endif
+
 
 #ifndef MAX_EDGES
 #define MAX_EDGES 48
diff --git a/group-connectivity.h b/group-connectivity.h
index 8c2f67288a78c18a9c67fe92f98b40af923342e5..1ad4100c246040d3528e21e899db9e512f3134ad 100644
--- a/group-connectivity.h
+++ b/group-connectivity.h
@@ -76,7 +76,8 @@ struct Tester : public AbstractTester {
       }
     }
   }
-  
+
+#if !USE_NEXT_FORB
   Mapping& unpack(size_t index, Mapping& ret) {
     size_t m = Ring::size - 1;
 
@@ -87,6 +88,7 @@ struct Tester : public AbstractTester {
 
     return ret;
   }
+#endif
 
   Mapping& cannonize(Mapping& map) {
     for (const auto &i : nonClassEdges) {
@@ -121,15 +123,44 @@ struct Tester : public AbstractTester {
 #endif
   }
 
+#if USE_NEXT_FORB
+  bool nextForb(Mapping& forb) {
+    for (size_t i = 0; i < edges; i++) {
+      T v = forb[i] + 1;
+      if (v >= Ring::size) {
+        forb.assign(i, 1);
+      } else {
+        forb.assign(i, v);
+        return true;
+      }
+    }
+
+    return false;
+  }
+#endif
 
   virtual bool run() {
     Mapping forb(edges);
     
+#if USE_NEXT_FORB
+    for (size_t i = 0; i < edges; i++)
+      forb.assign(i, 1);
+
+    do {
+      Mapping copy(forb);
+#if SAVE_MEMORY
+      classes[pack(cannonize(copy))] = true;
+#else
+      classes[pack(cannonize(copy))]++;
+#endif
+    } while (nextForb(forb));
+#else // ! USE_NEXT_FORB
     for (size_t i = 0; i < numForb; i++)
 #if SAVE_MEMORY
       classes[pack(cannonize(unpack(i, forb)))] = true;
 #else
       classes[pack(cannonize(unpack(i, forb)))]++;
+#endif
 #endif
 
     for (const auto &c : classes) if (!c) return (isConnected = false);