diff --git a/python/tools/scanner.py b/python/tools/scanner.py
index d58d9e443377f2bfad621229402b62d3c5ff38bd..2864741cb03298f6fe4ec94e5af04fa13994de61 100755
--- a/python/tools/scanner.py
+++ b/python/tools/scanner.py
@@ -114,10 +114,10 @@ def step(cur_h, cur_depth):
 
 def nextstep(cur_h, cur_depth, ok, nodes, arc=None, lines=[]):
     global done, all_nodes
+    if arc:
+        arc.remove()
+        del arc
     if nodes:
-        if arc:
-            arc.remove()
-            del arc
         for l in lines:
             l.set_color('#444444')
         snodes = NodeSet()
@@ -140,11 +140,14 @@ def exitcb(arg):
 exitbtn.on_clicked(exitcb)
 
 def restart(arg):
-    global collection, all_lines, points
+    global collection, all_lines, all_nodes, points, done
+    if done:
+        return
     for l in all_lines:
         l.remove()
         del l
     all_lines = []
+    all_nodes = NodeSet()
     if collection:
         collection.remove()
         del collection