diff --git a/hp4155/ADU_for_double_gate_devices_version_3/double_gate_ADU.py b/hp4155/ADU_for_double_gate_devices_version_3/double_gate_ADU.py
index bd4d20b07cdfcb75867f0b3cdfb92670fb10eb49..c7d8946a74df40248e03357beffb540890e8e3dd 100644
--- a/hp4155/ADU_for_double_gate_devices_version_3/double_gate_ADU.py
+++ b/hp4155/ADU_for_double_gate_devices_version_3/double_gate_ADU.py
@@ -3,10 +3,12 @@ sys.path.insert(0, './lib')
 sys.path.insert(0, '..') #append parent directory
 
 
+import hp4155a
 from interface import *
 from help import *
 import transfer
 import output
+import gatediode
 import configparser
 
 
@@ -47,7 +49,7 @@ def on_start_clicked(b):
             else: # Sequential measurement
                 transfer.SEQ(ui,device)
                 
-        if output_check.value == True:
+        if ui.output_check.value == True:
             if ui.output_gates.value == "VTG":
                output.VTG(ui,device)
             elif ui.output_gates.value == "VBG":
@@ -56,7 +58,7 @@ def on_start_clicked(b):
                 output.SEQ(ui,device)
                     
 
-        if gatediode_check.value == True:
+        if ui.gatediode_check.value == True:
             if ui.gatediode_gates.value == 'VTG':
                 gatediode.VTG(ui,device)
             else: #VBG
@@ -66,7 +68,7 @@ def on_start_clicked(b):
         change_state(ui.all_widgets)
             
 def on_export_ini_clicked(b):
-    with output:
+    with ui.output:
         change_state(ui.all_widgets)
         config = configparser.ConfigParser()
         default_filename = 'ADU_double_gate.ini'
@@ -165,7 +167,7 @@ def on_export_ini_clicked(b):
 
 
 def on_import_ini_clicked(b):
-    with output:
+    with ui.output:
         change_state(ui.all_widgets)
         #load values to the interface
         config = configparser.ConfigParser()
@@ -246,9 +248,9 @@ def on_import_ini_clicked(b):
         change_state(ui.all_widgets)
 
             
-button.on_click(on_start_clicked)
-import_ini_button.on_click(on_import_ini_clicked)
-export_ini_button.on_click(on_export_ini_clicked)
+ui.start.on_click(on_start_clicked)
+ui.import_ini.on_click(on_import_ini_clicked)
+ui.export_ini.on_click(on_export_ini_clicked)
 
 
 
diff --git a/hp4155/ADU_for_double_gate_devices_version_3/double_gate_ADU_interface.ipynb b/hp4155/ADU_for_double_gate_devices_version_3/double_gate_ADU_interface.ipynb
index e3ccb249d729249d744e33866a5226598c552efa..bccf7119845f923c3f56960e8137605718e24d62 100644
--- a/hp4155/ADU_for_double_gate_devices_version_3/double_gate_ADU_interface.ipynb
+++ b/hp4155/ADU_for_double_gate_devices_version_3/double_gate_ADU_interface.ipynb
@@ -9,7 +9,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "8c321db4c5e244cc9c3617416a9d77fe",
+       "model_id": "0879807dae214b789264fdcd4c264999",
        "version_major": 2,
        "version_minor": 0
       },
@@ -23,12 +23,12 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "6ee187f122a445de88a4261b5d316563",
+       "model_id": "6d4ea5ad1b6143a4ae91ee17406184bf",
        "version_major": 2,
        "version_minor": 0
       },
       "text/plain": [
-       "HBox(children=(Checkbox(value=True, description='Transfer Curve', indent=False), Checkbox(value=True, descript…"
+       "HBox(children=(Checkbox(value=True, description='Transfer', indent=False), Checkbox(value=True, description='O…"
       ]
      },
      "metadata": {},
@@ -37,7 +37,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "405c3af151294accb2cebd393d74c484",
+       "model_id": "92b167e872da4970ac54d2be519e3f98",
        "version_major": 2,
        "version_minor": 0
       },
@@ -51,7 +51,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "0128321641484d0499c75fa66643df96",
+       "model_id": "3d99607bed9d4b9e886dad6d5a98062e",
        "version_major": 2,
        "version_minor": 0
       },
@@ -65,7 +65,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "a9af785a10d44cbb95cdcc833ab60df4",
+       "model_id": "e6f9253c0a1b41b6ad3476cd030f6b8f",
        "version_major": 2,
        "version_minor": 0
       },
@@ -84,7 +84,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "96ff60d6-a9c5-4f9c-b28e-ea6003e6e8a8",
+   "id": "3d0c5404-a1c6-40f9-bffd-625199c945a7",
    "metadata": {},
    "outputs": [],
    "source": []
diff --git a/hp4155/ADU_for_double_gate_devices_version_3/lib/gatediode.py b/hp4155/ADU_for_double_gate_devices_version_3/lib/gatediode.py
index b22058e98024aa33aba78ea05d58a54b0c56af24..68352d61d34c4e5b19940ca1c8535b970753c455 100644
--- a/hp4155/ADU_for_double_gate_devices_version_3/lib/gatediode.py
+++ b/hp4155/ADU_for_double_gate_devices_version_3/lib/gatediode.py
@@ -49,7 +49,9 @@ def VTG(ui,device):
         variables_list = ['VTG','ITG']
         device.variables_to_save(variables_list)
 
-         plotted_variables = graph_tool(ui.plot_gatediode,ui.sample.width.value,device)
+        plotted_variables = graph_tool(ui.plot_gatediode,ui.sample.width.value,device)
+
+        device.error_occured()
         
         device.single_measurement()
         while device.operation_completed()==False:
@@ -119,7 +121,7 @@ def VBG(ui,device):
     )
 
     try:
-        device.setup_smu(ui.sample.top_gate.value,smu_top_gate)
+        device.setup_smu(ui.sample.top_gate.value,smu_back_gate)
         device.setup_smu(ui.sample.source.value,smu_source)
     
         # disable back gate smu
@@ -131,10 +133,12 @@ def VBG(ui,device):
         device.setup_var1(var1)
         device.integration_time(ui.integration_gatediode.value)
         
-        variables_list = ['VBG','VTG']
+        variables_list = ['VBG','IBG']
         device.variables_to_save(variables_list)
 
-         plotted_variables = graph_tool(ui.plot_gatediode,ui.sample.width.value,device)
+        plotted_variables = graph_tool(ui.plot_gatediode,ui.sample.width.value,device)
+
+        device.error_occured()
         
         device.single_measurement()
         while device.operation_completed()==False:
diff --git a/hp4155/ADU_for_double_gate_devices_version_3/lib/help.py b/hp4155/ADU_for_double_gate_devices_version_3/lib/help.py
index 180fd97c9a9ab0657bc0d787d0a52ecf7bef3859..40f602d3486fafb1df850701baf00481da19d4e2 100644
--- a/hp4155/ADU_for_double_gate_devices_version_3/lib/help.py
+++ b/hp4155/ADU_for_double_gate_devices_version_3/lib/help.py
@@ -7,6 +7,7 @@ import tkinter as tk
 from tkinter import filedialog
 import tkinter.messagebox
 import copy
+import os 
 
 import pandas as pd
 
@@ -167,12 +168,12 @@ def graph_tool(plot_config,width,device): # the plot config object from the inte
         device.display_variable('Y1',"A"+plot_config.y1.value)
     else:
         device.display_variable('Y1',plot_config.y1.value)
-    device.axis_scale('Y1',plot_config.y1.value)
+    device.axis_scale('Y1',plot_config.y1_scale.value)
     device.display_variable_min_max('Y1','MIN',plot_config.y1_min.value)
     device.display_variable_min_max('Y1','MAX',plot_config.y1_max.value)
 
     if plot_config.y2.value!= "None":
-        if params["PLOT"]["y2_scale"]=='LOG':
+        if plot_config.y2_scale.value=='LOG':
             device.display_variable('Y2',"A"+plot_config.y2.value)
         else:
             device.display_variable('Y2',plot_config.y2.value)
@@ -214,6 +215,8 @@ def create_file(filename):
 
     root.destroy()
 
+    return file
+
 def write_sample_information(sample,file):
     file.write(f"Series:{sample.processing_number.value}"+"\n")
     file.write(f"Sample:{sample.sample.value}"+"\n")
@@ -225,7 +228,7 @@ def create_plot(plot_config,df,file,fig_title,legend_title,save):
     labels = df["label"].unique()
     colors = plt.cm.tab20.colors[:len(labels)]
     
-    fig1,ax1 = plt.subplots(figsize = (10,6))
+    fig,ax1 = plt.subplots(figsize = (10,6))
     x_col,x_label = column_to_plot(plot_config.x.value)
     y1_col, y1_label = column_to_plot(plot_config.y1.value)
 
@@ -233,7 +236,7 @@ def create_plot(plot_config,df,file,fig_title,legend_title,save):
         ax1.set_yscale('log')
         for color, label in zip(colors,labels):
             subset = df[df["label"]== label]
-            ax1.plot(subset[x_col],subset[y_col].abs(),color = color,label = label)
+            ax1.plot(subset[x_col],subset[y1_col].abs(),color = color,label = label)
     else:
         for color, label in zip(colors,labels):
             subset = df[df["label"]== label]
@@ -259,10 +262,10 @@ def create_plot(plot_config,df,file,fig_title,legend_title,save):
     # now for the y2 axis
     if plot_config.y2.value!= "None":
         fig,ax2 = plt.subplots(figsize = (10,6))
-        y2_col, y2_label = column_to_plot(plot_config.y2_value)
+        y2_col, y2_label = column_to_plot(plot_config.y2.value)
 
         if plot_config.y2_scale.value == 'LOG':
-            ax1.set_yscale('log')
+            ax2.set_yscale('log')
             for color, label in zip(colors,labels):
                 subset = df[df["label"]== label]
                 ax2.plot(subset[x_col],subset[y2_col].abs(),color = color,label = label)
@@ -272,7 +275,7 @@ def create_plot(plot_config,df,file,fig_title,legend_title,save):
                 ax2.plot(subset[x_col],subset[y2_col],color = color,label = label)
 
         ax2.set_xlabel(x_label)
-        ax2.set_ylabel(y1_label)
+        ax2.set_ylabel(y2_label)
         ax2.set_title(fig_title,fontweight = 'bold')
         ax2.grid(True)
         ax2.legend(
diff --git a/hp4155/ADU_for_double_gate_devices_version_3/lib/output.py b/hp4155/ADU_for_double_gate_devices_version_3/lib/output.py
index 7e25b0b0c22185b68c1d8309045522a4053b257f..dbc7fd30d66cfef0568f6fd9e3346d7b413d12d6 100644
--- a/hp4155/ADU_for_double_gate_devices_version_3/lib/output.py
+++ b/hp4155/ADU_for_double_gate_devices_version_3/lib/output.py
@@ -28,7 +28,7 @@ def VTG(ui,device):
     smu_back_gate.update(vname = 'VBG',iname='IBG',mode = 'COMM',func = 'CONS')
 
     smu_drain = device.smu_dict()
-    smu_drain = device.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR1')
+    smu_drain.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR1')
 
     # setup VAR1
     var1 = device.var1_dict()
@@ -50,7 +50,7 @@ def VTG(ui,device):
         pcomp=ui.Vtg_output.pcomp.value,
     )
 
-     try:
+    try:
         device.setup_smu(ui.sample.top_gate.value,smu_top_gate)
         device.setup_smu(ui.sample.drain.value,smu_drain)
         device.setup_smu(ui.sample.back_gate.value,smu_back_gate)
@@ -63,7 +63,9 @@ def VTG(ui,device):
         variables_list = ['VDS','ID','VTG','ITG']
         device.variables_to_save(variables_list)
 
-        plotted_variables = graph_tool(plot_output,ui.sample.width.value,device)
+        plotted_variables = graph_tool(ui.plot_output,ui.sample.width.value,device)
+
+        device.error_occured()
 
         device.single_measurement()
         
@@ -113,12 +115,12 @@ def VTG(ui,device):
     df.to_csv(file,sep=" ",mode='a')
 
     if ui.sample.quick.value == False:
-        df["label"] = df.apply(lambda row:f"VTG = {row["VTG/V"]} (V)",axis = 1) # assign labels
+        df["label"] = df.apply(lambda row:f"VTG = {row['VTG/V']} (V)",axis = 1) # assign labels
         create_plot(ui.plot_output,df,file,"Top Gate Output Measurement", "Swept VTG voltages:",ui.sample.save_fig.value)
 
 
 def VBG(ui,device):
-     device.del_user_functions() # delete all user functions 
+    device.del_user_functions() # delete all user functions 
     device.clear_error_stack() # clear error stack
     # setup the smus
 
@@ -136,7 +138,7 @@ def VBG(ui,device):
     smu_back_gate.update(vname = 'VBG',iname='IBG',mode = 'V',func = 'VAR2')
 
     smu_drain = device.smu_dict()
-    smu_drain = device.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR1')
+    smu_drain.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR1')
 
     # setup VAR1
     var1 = device.var1_dict()
@@ -158,7 +160,7 @@ def VBG(ui,device):
         pcomp=ui.Vbg_output.pcomp.value,
     )
 
-     try:
+    try:
         device.setup_smu(ui.sample.top_gate.value,smu_top_gate)
         device.setup_smu(ui.sample.drain.value,smu_drain)
         device.setup_smu(ui.sample.back_gate.value,smu_back_gate)
@@ -173,6 +175,8 @@ def VBG(ui,device):
         device.variables_to_save(variables_list)
 
         plotted_variables = graph_tool(ui.plot_output,ui.sample.width.value,device)
+
+        device.error_occured()
         
         device.single_measurement()
         
@@ -224,16 +228,18 @@ def VBG(ui,device):
     df.to_csv(file,sep=" ",mode='a')
 
     if ui.sample.quick.value == False:
-        df["label"] = df.apply(lambda row:f"VBG = {row["VBG/V"]} (V)",axis = 1) # assign labels
-        create_plot(ui,df,file,"Back Gate Output Measurement", "Swept VBG voltages:",ui.sample.save_fig.value)
+        df["label"] = df.apply(lambda row:f"VBG = {row['VBG/V']} (V)",axis = 1) # assign labels
+        create_plot(ui.plot_output,df,file,"Back Gate Output Measurement", "Swept VBG voltages:",ui.sample.save_fig.value)
 
 def SEQ(ui,device):
+    device.del_user_functions() # delete all user functions 
+    device.clear_error_stack() # clear error stack
     norm = normalization_factor(ui.sample.width.value)
     points_VTG = number_of_points(ui.Vtg_output)
     points_VBG = number_of_points(ui.Vbg_output)
 
     try:
-        values_VBG = np.linspace(ui.Vbg_output.start.value, ui.Vbg_output.stop.value,num = points,endpoint = True)
+        values_VBG = np.linspace(ui.Vbg_output.start.value, ui.Vbg_output.stop.value,num = points_VBG,endpoint = True)
     except:
         error_box("Invalid VBG values!")
         return
@@ -248,7 +254,7 @@ def SEQ(ui,device):
     smu_back_gate.update(vname = 'VBG',iname='IBG',mode = 'V',func = 'CONS') 
 
     smu_drain = device.smu_dict()
-    smu_drain = device.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR1')
+    smu_drain.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR1')
 
     # setup VAR1
     var1 = device.var1_dict()
@@ -285,7 +291,9 @@ def SEQ(ui,device):
         device.variables_to_save(variables_list)
 
         plotted_variables = graph_tool(ui.plot_output,ui.sample.width.value,device)
-        for i,value in enumerate(VBG_values):
+
+        device.error_occured()
+        for i,value in enumerate(values_VBG):
             cons = device.cons_smu_dict()
             cons.update(comp = ui.Vbg_output.comp.value, value = value)
             device.setup_cons_smu(ui.sample.back_gate.value,cons)
@@ -319,14 +327,14 @@ def SEQ(ui,device):
     default_filename = f"{ui.sample.sample.value}_{ui.sample.field.value}_{ui.sample.device.value}_BOTH_GATES_SEQ_A.txt"
     file = create_file(default_filename)
 
-     with open(file,'w') as f:
+    with open(file,'w') as f:
         date = str(datetime.today().replace(microsecond=0))
         f.write(f"output Curve at {date}"+"\n")
         write_sample_information(ui.sample,f)
         f.write("Sweeping Gate:VTG,VBG sequentially"+"\n\n")
         f.write('Parameters\n')
         f.write(f"VBG from {ui.Vbg_output.start.value}V to {ui.Vbg_output.stop.value}V with step {ui.Vbg_output.step.value}V"+"\n")
-        f.write(f"VTG from {ui.Vtg_output.start.value]}V to {ui.Vtg_output.stop.value}V with step {ui.Vbg_output.step.value}V"+"\n")
+        f.write(f"VTG from {ui.Vtg_output.start.value}V to {ui.Vtg_output.stop.value}V with step {ui.Vbg_output.step.value}V"+"\n")
         f.write(f"VDS from {ui.Vds_output.start.value}V to {ui.Vds_output.stop.value}V with step {ui.Vds_output.step.value}V"+"\n")
         
         f.write(f"Back Gate Current Compliance/A:{ui.Vbg_output.comp.value}"+"\n")
@@ -346,7 +354,7 @@ def SEQ(ui,device):
     df.to_csv(file,sep=" ",mode='a')
 
     if ui.sample.quick.value == False:
-        df["label"] = df.apply(lambda row:f"VTG = {row["VTG/V"]} (V), VBG = {row["VBG/V"]} (V)",axis = 1) # assign labels
+        df["label"] = df.apply(lambda row:f"VTG = {row['VTG/V']} (V), VBG = {row['VBG/V']} (V)",axis = 1) # assign labels
         create_plot(ui.plot_output,df,file,"Sequential Sweep of Both Gates Output Measurement", "Swept voltages:",ui.sample.save_fig.value)
         
         
diff --git a/hp4155/ADU_for_double_gate_devices_version_3/lib/transfer.py b/hp4155/ADU_for_double_gate_devices_version_3/lib/transfer.py
index 245290aee96690b57e81cff0c55e55ac419e19cc..d9851d71b5fbe4f447bd2fcbc27465118cc008fe 100644
--- a/hp4155/ADU_for_double_gate_devices_version_3/lib/transfer.py
+++ b/hp4155/ADU_for_double_gate_devices_version_3/lib/transfer.py
@@ -27,7 +27,7 @@ def VTG(ui,device):
     smu_back_gate.update(vname = 'VBG',iname='IBG',mode = 'COMM',func = 'CONS')
 
     smu_drain = device.smu_dict()
-    smu_drain = device.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR2')
+    smu_drain.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR2')
 
     # setup VAR1
     var1 = device.var1_dict()
@@ -64,6 +64,8 @@ def VTG(ui,device):
         device.variables_to_save(variables_list)
     
         plotted_variables = graph_tool(ui.plot_transfer,ui.sample.width.value,device)
+
+        device.error_occured()
         
         device.single_measurement()
         while device.operation_completed()==False:
@@ -113,7 +115,7 @@ def VTG(ui,device):
     df.to_csv(file,sep=" ",mode='a')
 
     if ui.sample.quick.value == False:
-        df["label"] = df.apply(lambda row:f"VDS = {row["VDS/V"]} (V)",axis = 1) # assign labels
+        df["label"] = df.apply(lambda row:f"VDS = {row['VDS/V']} (V)",axis = 1) # assign labels
         create_plot(ui.plot_transfer,df,file,"Top Gate Transfer Measurement", "Swept VDS voltages:",ui.sample.save_fig.value)
 
 def VBG(ui,device):
@@ -134,7 +136,7 @@ def VBG(ui,device):
     smu_back_gate.update(vname = 'VBG',iname='IBG',mode = 'V',func = 'VAR1')
 
     smu_drain = device.smu_dict()
-    smu_drain = device.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR2')
+    smu_drain.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR2')
 
     
     var1 = device.var1_dict()
@@ -171,6 +173,8 @@ def VBG(ui,device):
         device.variables_to_save(variables_list)
 
         plotted_variables = graph_tool(ui.plot_transfer,ui.sample.width.value,device)
+
+        device.error_occured()
         
         device.single_measurement()
         
@@ -222,12 +226,12 @@ def VBG(ui,device):
     df.to_csv(file,sep=" ",mode='a')
 
     if ui.sample.quick.value == False:
-        df["label"] = df.apply(lambda row:f"VDS = {row["VDS/V"]} (V)",axis = 1) # assign labels
+        df["label"] = df.apply(lambda row:f"VDS = {row['VDS/V']} (V)",axis = 1) # assign labels
         create_plot(ui.plot_transfer,df,file,"Back Gate Transfer Measurement", "Swept VDS voltages:",ui.sample.save_fig.value)
 
 
 # Simultaneously bóth gates
-def SIM():
+def SIM(ui,device):
     device.del_user_functions() # delete all user functions 
     device.clear_error_stack() # clear error stack
     # setup the smus
@@ -245,7 +249,7 @@ def SIM():
     smu_back_gate.update(vname = 'VBG',iname='IBG',mode = 'V',func = 'VARD')
 
     smu_drain = device.smu_dict()
-    smu_drain = device.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR2')
+    smu_drain.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR2')
 
     
     var1 = device.var1_dict()
@@ -271,7 +275,7 @@ def SIM():
     ratio,offset = calculate_line(ui.Vtg_transfer,ui.Vbg_transfer)
     
     # update VBG step
-    ui.Vbg_transfer.step.value = Decimal(str(ratio)) * Decimal(str(Vtg_transfer.step.value))
+    ui.Vbg_transfer.step.value = Decimal(str(ratio)) * Decimal(str(ui.Vtg_transfer.step.value))
 
     vard = device.vard_dict()
     vard.update(
@@ -298,6 +302,8 @@ def SIM():
 
         plotted_variables = graph_tool(ui.plot_transfer,ui.sample.width.value,device)
         
+        device.error_occured()
+        
         device.single_measurement()
         
         while device.operation_completed()==False:
@@ -332,7 +338,7 @@ def SIM():
         f.write("Sweeping Gate:VTG,VBG simultaneously"+"\n\n")
         f.write('Parameters\n')
         f.write(f"VBG from {ui.Vbg_transfer.start.value}V to {ui.Vbg_transfer.stop.value}V with step {ui.Vbg_transfer.step.value}V"+"\n")
-        f.write(f"VTG from {ui.Vtg_transfer.start.value]}V to {ui.Vtg_transfer.stop.value}V with step {ui.Vbg_transfer.step.value}V"+"\n")
+        f.write(f"VTG from {ui.Vtg_transfer.start.value}V to {ui.Vtg_transfer.stop.value}V with step {ui.Vbg_transfer.step.value}V"+"\n")
         f.write(f"VDS from {ui.Vds_transfer.start.value}V to {ui.Vds_transfer.stop.value}V with step {ui.Vds_transfer.step.value}V"+"\n")
         
         if ui.Vbg_transfer.pcomp.value==0:
@@ -355,17 +361,19 @@ def SIM():
     df.to_csv(file,sep=" ",mode='a')
 
     if ui.sample.quick.value == False:
-        df["label"] = df.apply(lambda row:f"VDS = {row["VDS/V"]} (V)",axis = 1) # assign labels
+        df["label"] = df.apply(lambda row:f"VDS = {row['VDS/V']} (V)",axis = 1) # assign labels
         create_plot(ui.plot_transfer,df,file,"Simultaneous Sweep of Both Gates Transfer Measurement", "Swept VDS voltages:",ui.sample.save_fig.value)
 
 def SEQ(ui,device):
-    
+    device.del_user_functions() # delete all user functions 
+    device.clear_error_stack() # clear error stack
     norm = normalization_factor(ui.sample.width.value)
     points_VDS = number_of_points(ui.Vds_transfer)
     points_VBG = number_of_points(ui.Vbg_transfer)
 
+
     try:
-        values_VBG = np.linspace(ui.Vbg_transfer.start.value,ui.Vbg_transfer.stop.value,num = points, endpoint = True)
+        values_VBG = np.linspace(ui.Vbg_transfer.start.value,ui.Vbg_transfer.stop.value,num = points_VBG, endpoint = True)
     except:
         error_box("Invalid VBG values!")
         return
@@ -380,7 +388,7 @@ def SEQ(ui,device):
     smu_back_gate.update(vname = 'VBG',iname='IBG',mode = 'V',func = 'CONS') # Only VTG is swept
 
     smu_drain = device.smu_dict()
-    smu_drain = device.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR2')
+    smu_drain.update(vname='VDS',iname='ID',mode = 'V',func = 'VAR2')
 
 
     # setup VAR1
@@ -398,7 +406,7 @@ def SEQ(ui,device):
     var2.update(
         start=ui.Vds_transfer.start.value,
         step=ui.Vds_transfer.step.value,
-        points=points,
+        points=points_VDS,
         comp=ui.Vds_transfer.comp.value,
         pcomp=ui.Vds_transfer.pcomp.value,
     )
@@ -419,8 +427,10 @@ def SEQ(ui,device):
 
         plotted_variables = graph_tool(ui.plot_transfer,ui.sample.width.value,device)
 
+        device.error_occured()
+
         # In the end VBG is swept
-        for i,value in enumerate(VBG_values):
+        for i,value in enumerate(values_VBG):
             cons = device.cons_smu_dict()
             cons.update(comp = ui.Vbg_transfer.comp.value, value = value)
             device.setup_cons_smu(ui.sample.back_gate.value,cons)
@@ -461,7 +471,7 @@ def SEQ(ui,device):
         f.write("Sweeping Gate:VTG,VBG sequentially"+"\n\n")
         f.write('Parameters\n')
         f.write(f"VBG from {ui.Vbg_transfer.start.value}V to {ui.Vbg_transfer.stop.value}V with step {ui.Vbg_transfer.step.value}V"+"\n")
-        f.write(f"VTG from {ui.Vtg_transfer.start.value]}V to {ui.Vtg_transfer.stop.value}V with step {ui.Vbg_transfer.step.value}V"+"\n")
+        f.write(f"VTG from {ui.Vtg_transfer.start.value}V to {ui.Vtg_transfer.stop.value}V with step {ui.Vbg_transfer.step.value}V"+"\n")
         f.write(f"VDS from {ui.Vds_transfer.start.value}V to {ui.Vds_transfer.stop.value}V with step {ui.Vds_transfer.step.value}V"+"\n")
         
         f.write(f"Back Gate Current Compliance/A:{ui.Vbg_transfer.comp.value}"+"\n")
@@ -482,9 +492,9 @@ def SEQ(ui,device):
 
     if ui.sample.quick.value == False:
         if ui.plot_transfer.x.value == 'VTG':
-            df["label"] = df.apply(lambda row:f"VDS = {row["VDS/V"]} (V), VBG = {row["VBG/V"]} (V)",axis = 1) # assign labels
+            df["label"] = df.apply(lambda row:f"VDS = {row['VDS/V']} (V), VBG = {row['VBG/V']} (V)",axis = 1) # assign labels
             
         else:
-            df["label"] = df.apply(lambda row:f"VDS = {row["VDS/V"]} (V), VTG = {row["VTG/V"]} (V)",axis = 1) # assign labels
+            df["label"] = df.apply(lambda row:f"VDS = {row['VDS/V']} (V), VTG = {row['VTG/V']} (V)",axis = 1) # assign labels
 
         create_plot(ui.plot_transfer,df,file,"Sequential Sweep of Both Gates Transfer Measurement", "Swept voltages:",ui.sample.save_fig.value)
\ No newline at end of file