diff --git a/window.cpp b/window.cpp
index 4969ccda60e3cf50c5d244539e99918d2568db9e..0f03bc3e157067e01289136d0cde2bdf79078cc7 100644
--- a/window.cpp
+++ b/window.cpp
@@ -85,53 +85,52 @@ void Window::solveButtonClicked()
                     validNrs.push_back(i);
             if (validNrs.size() == 0)
             {
+                if (hist.size() <= 0)
+                    return;
                 hist.pop_back();
                 continue;
             }
             backtracking = false;
-            int rndNr = rand() % validNrs.size(); // choose a random number;
+            int rndNr = rand() % validNrs.size();        // choose a random number;
             hist.back().cell->collapse(validNrs[rndNr]); // collapse cell with chosen number;
             hist.back().blocked[validNrs[rndNr]]++;
         }
-        else
+        std::vector<Cell *> b; // vector of cells with least entropy
+        int minEtropy = 10;
+        for (auto &cell : grid)
         {
-            std::vector<Cell *> b; // vector of cells with least entropy
-            int minEtropy = 10;
-            for (auto &cell : grid)
+            if (cell.collapsed)
+                continue;
+            else if (cell.possibleStates < minEtropy)
             {
-                if (cell.collapsed)
-                    continue;
-                else if (cell.possibleStates < minEtropy)
-                {
-                    minEtropy = cell.possibleStates;
-                    b.clear();
-                    b.push_back(&cell);
-                }
-                else if (cell.possibleStates == minEtropy)
-                {
-                    b.push_back(&cell);
-                }
+                minEtropy = cell.possibleStates;
+                b.clear();
+                b.push_back(&cell);
             }
-            if (b.size() == 0) // if b is empty -> solved
-                return;
-
-            else if (minEtropy == 0)
+            else if (cell.possibleStates == minEtropy)
             {
-                backtracking = true;
-                continue;
+                b.push_back(&cell);
             }
+        }
+        if (b.size() == 0) // if b is empty -> solved
+            return;
 
-            int rndCell = rand() % b.size(); // choose a random cell
-            std::vector<int> validNrs;
-            for (int i = 0; i < 9; i++)
-            {
-                if (!b[rndCell]->blocked[i])
-                    validNrs.push_back(i);
-            }
-            int rndNr = rand() % validNrs.size(); // choose a random number;
-            hist.push_back(History(b[rndCell], b[rndCell]->blocked, validNrs[rndNr]));
-            b[rndCell]->collapse(validNrs[rndNr]); // collapse that random cell with chosen number;
+        else if (minEtropy == 0)
+        {
+            backtracking = true;
+            continue;
+        }
+
+        int rndCell = rand() % b.size(); // choose a random cell
+        std::vector<int> validNrs;
+        for (int i = 0; i < 9; i++)
+        {
+            if (!b[rndCell]->blocked[i])
+                validNrs.push_back(i);
         }
+        int rndNr = rand() % validNrs.size(); // choose a random number;
+        hist.push_back(History(b[rndCell], validNrs[rndNr]));
+        b[rndCell]->collapse(validNrs[rndNr]); // collapse that random cell with chosen number;
     }
 }
 void Window::clearButtonClicked()
diff --git a/window.h b/window.h
index b2186b1035c8ef3e3b1eb3d68c67a356ac86df21..f4e57adeb5b719bc2b45b6d1138160a748cc8c0d 100644
--- a/window.h
+++ b/window.h
@@ -26,10 +26,10 @@ private:
     {
         Cell *cell;
         std::array<int, 9> blocked;
-        History(Cell *c, std::array<int,9> in, int choice)
+        History(Cell *c, int choice)
         {
             cell = c;
-            blocked =in;
+            blocked = c->blocked;
             blocked[choice] ++;
         }
     };