diff --git a/GUI_main.py b/GUI_main.py
index 5726983d55c96d38958078f5dbcc2147a2c47c8f..e1fecc12cb0c395c6dc5971fcdadfc4076690fa9 100644
--- a/GUI_main.py
+++ b/GUI_main.py
@@ -50,11 +50,11 @@ the corresponding picture. This mask can also be corrected using the
 usual buttons (because the Cell Correspondance makes also mistakes). 
 
 """
-import os
 import sys
 import numpy as np
 import pandas as pd
 import h5py
+import skimage
 
 # For writing excel files
 #from openpyxl import load_workbook
@@ -116,7 +116,11 @@ from PlotCanvas import PlotCanvas
 
 import Extract as extr
 from image_loader import load_image
-    
+from segment import segment
+import neural_network as nn
+
+
+
 
 class NavigationToolbar(NavigationToolbar):
     """This is the standard matplotlib toolbar but only the buttons
@@ -316,10 +320,7 @@ class App(QMainWindow):
         button out of focus when the user clicks somewhere
         on the gui. (to unfocus the buttons)
         """
-        self.button_timeindex.clearFocus()
-        if self.button_SetThreshold.isEnabled():
-            self.button_SetThreshold.clearFocus()
-            
+        self.button_timeindex.clearFocus()            
         if self.button_SetSegmentation.isEnabled():
             self.button_SetSegmentation.clearFocus()
         
@@ -631,7 +632,6 @@ class App(QMainWindow):
             
             # Center of mass
             y,x = mask.nonzero()
-            # sample = np.random.choice(len(x), size=50, replace=True)
             com_x = np.mean(x)
             com_y = np.mean(y)
             
@@ -666,7 +666,6 @@ class App(QMainWindow):
 # -----------------------------------------------------------------------------
 # NEURAL NETWORK
     def ShowHideCNNbuttons(self):
-        
         """hide and show the buttons corresponding to the neural network.
             this function is called by the button CNN which is hidden. But
             if activated in the InitLayout.py then you can have a button
@@ -678,7 +677,6 @@ class App(QMainWindow):
             self.button_segment.setVisible(True)
             self.button_savesegmask.setVisible(True)
             self.button_threshold.setVisible(True)
-            self.button_SetThreshold.setVisible(True)
             self.button_savethresholdmask.setVisible(True)
             self.button_SetSegmentation.setVisible(True)
 
@@ -687,7 +685,6 @@ class App(QMainWindow):
             self.button_segment.setVisible(False)
             self.button_savesegmask.setVisible(False)
             self.button_threshold.setVisible(False)
-            self.button_SetThreshold.setVisible(False)
             self.button_savethresholdmask.setVisible(False)
             self.button_SetSegmentation.setVisible(False)
             
@@ -755,23 +752,18 @@ class App(QMainWindow):
                         seg_val = 10
                     self.PredThreshSeg(t, dlg.listfov.row(item), thr_val, seg_val)
                     
-                    # if tracker has been checked then apply it
+                    # apply tracker if wanted and if not at first time
                     if dlg.tracking_checkbox.isChecked():
-                        if t != time_value1:
-                            temp_mask = self.reader.CellCorrespondance(t, dlg.listfov.row(item))
-                            self.reader.SaveMask(t,dlg.listfov.row(item), temp_mask)
-                        
-                        else:
-                            temp_mask = self.reader.LoadSeg(t, dlg.listfov.row(item))
-                            self.reader.SaveMask(t,dlg.listfov.row(item), temp_mask)
+                        temp_mask = self.reader.CellCorrespondance(t, dlg.listfov.row(item))
+                        self.reader.SaveMask(t,dlg.listfov.row(item), temp_mask)
             
             self.ReloadThreeMasks()
             
         self.m.UpdatePlots()
         self.ClearStatusBar()
-        self.EnableCNNButtons()
         self.Enable(self.button_cnn)
-    
+        self.EnableCNNButtons()
+
     
     def PredThreshSeg(self, timeindex, fovindex, thr_val, seg_val):
           """
@@ -782,12 +774,30 @@ class App(QMainWindow):
           Then it segments the thresholded prediction and saves the
           segmentation. 
           """
-          self.reader.LaunchPrediction(timeindex, fovindex)
-          self.m.ThresholdMask = self.reader.ThresholdPred(thr_val, timeindex,fovindex)
-          self.reader.SaveThresholdMask(timeindex, fovindex, self.m.ThresholdMask)
-          self.m.SegmentedMask = self.reader.Segment(seg_val, timeindex,fovindex)
-          self.reader.SaveSegMask(timeindex, fovindex, self.m.SegmentedMask)
-          self.reader.SaveMask(timeindex, fovindex, self.m.SegmentedMask)
+          im = self.reader.LoadOneImage(timeindex, fovindex)
+          pred = self.LaunchPrediction(im)
+          thresh = self.ThresholdPred(thr_val, pred)
+          seg = segment(thresh, pred, seg_val)
+          self.reader.SaveMask(timeindex, fovindex, seg)
+          
+    def LaunchPrediction(self, im):
+        """It launches the neural neutwork on the current image and creates 
+        an hdf file with the prediction for the time T and corresponding FOV. 
+        """
+        im = skimage.exposure.equalize_adapthist(im)
+        im = im*1.0;	
+        pred = nn.prediction(im)
+        return pred
+
+
+    def ThresholdPred(self, thvalue, pred):     
+        """Thresholds prediction with value"""
+        if thvalue == None:
+            thresholdedmask = nn.threshold(pred)
+        else:
+            thresholdedmask = nn.threshold(pred,thvalue)
+        return thresholdedmask
+
             
     
     def SelectChannel(self, index):
@@ -1047,53 +1057,6 @@ class App(QMainWindow):
         """saves the segmented mask
         """
         self.reader.SaveSegMask(self.Tindex, self.FOVindex, self.m.plotmask)
-    
-        
-    def ThresholdBoxCheck(self):
-        """if the buttons is checked it shows the thresholded version of the 
-        prediction, if it is not available it justs displays a null array.
-        The buttons for the setting a threshold a value and to save it are then
-        activated once this button is enabled.
-        """
-        if self.button_threshold.isChecked():
-            self.Disable(self.button_threshold)
-            self.m.ThresholdMask = self.reader.LoadThreshold(self.Tindex, self.FOVindex)
-            
-            self.m.currmask.set_data(self.m.ThresholdMask)
-            self.m.ax.draw_artist(self.m.currplot)
-            self.m.ax.draw_artist(self.m.currmask)
-            self.m.update()
-            self.m.flush_events()
-            
-            self.button_SetThreshold.setEnabled(True)
-            self.button_savethresholdmask.setEnabled(True)
-            
-        else:
-            self.m.updatedata()
-            self.button_SetThreshold.setEnabled(False)
-            self.button_savethresholdmask.setEnabled(False)
-            self.Enable(self.button_threshold)
-
-
-    def ThresholdPrediction(self):
-        # update the plots to display the thresholded view
-        thresholdvalue = float(self.button_SetThreshold.text())
-        
-        self.m.ThresholdMask = self.reader.ThresholdPred(
-            thresholdvalue, 
-            self.Tindex,self.FOVindex)
-        
-        self.m.currmask.set_data(self.m.ThresholdMask)
-        self.m.ax.draw_artist(self.m.currplot)
-        self.m.ax.draw_artist(self.m.currmask)
-        self.m.update()
-        self.m.flush_events()
-      
-        
-    def ButtonSaveThresholdMask(self):
-        """saves the thresholed mask
-        """
-        self.reader.SaveThresholdMask(self.Tindex, self.FOVindex, self.m.ThresholdMask)
 
         
     def ChangePreviousFrame(self):
@@ -1588,7 +1551,7 @@ class App(QMainWindow):
 
 
     def EnableCNNButtons(self):
-        if self.reader.TestPredExisting(self.Tindex, self.FOVindex):
+        if self.reader.TestTimeExist(self.Tindex, self.FOVindex):
             self.button_threshold.setEnabled(True)
             self.button_segment.setEnabled(True)
             self.button_cellcorespondance.setEnabled(True)
diff --git a/disk/InteractionDisk_temp.py b/disk/InteractionDisk_temp.py
index 715fab53c7b72d3308a24a1e1b421188d01a254b..c7625792d93b1002f67b5c569a06631d09d26a0e 100644
--- a/disk/InteractionDisk_temp.py
+++ b/disk/InteractionDisk_temp.py
@@ -3,8 +3,8 @@
 """
 Created on Tue Oct 15 15:00:29 2019
 
-This program reads out the images from the nd2 file and creates or 
-reads the hdf file containing the segmentation.
+This file handles all interactions with the hdf and image files, such as 
+loading or saving a particular image.
 """
 from nd2reader import ND2Reader
 import numpy as np
@@ -13,10 +13,8 @@ import h5py
 import os.path
 import skimage
 import skimage.io
-import neural_network as nn
 import pytiff
 import hungarian as hu
-from segment import segment
 
 
 class Reader:
@@ -92,17 +90,11 @@ class Reader:
         self.InitLabels()
         
         self.default_channel = 0
-        
         self.name = self.hdfpath
-        
-        self.predictname = ''
-        self.thresholdname = ''
-        self.segmentname = ''
-                    
+                            
         # create an new hfd5 file if no one existing already
         self.Inithdf()
 
-
         
     def InitLabels(self):
         """Create two lists containing all the possible fields of view and time
@@ -128,16 +120,9 @@ class Reader:
             if not self.hdfpath:
                 self.hdfpath = self.newhdfpath
             filenamewithpath, extension = os.path.splitext(self.hdfpath)
-            
-            if extension == ".h5":
-                temp = self.hdfpath[:-3]
                 
-                self.thresholdname = temp + '_thresholded' + '.h5'
-                self.segmentname = temp + '_segmented' + '.h5'
-                self.predictname = temp + '_predicted' + '.h5'
-                
-            elif extension == '.tiff' or extension == '.tif':
-                #SJR: Careful, self.hdfpath is a tif file
+            # If mask file is a tiff file
+            if extension == '.tiff' or extension == '.tif':
                 im = skimage.io.imread(self.hdfpath)
                 imdims = im.shape
                 
@@ -156,21 +141,6 @@ class Reader:
                             hf.create_dataset('/FOV0/T{}'.format(i), 
                                               data = im[i,:,:], compression = 'gzip')
 
-                self.thresholdname = filenamewithpath + '_thresholded' + '.h5'
-                hf = h5py.File(self.thresholdname,'w')
-                hf.create_group('FOV0')
-                hf.close()
-    
-                self.segmentname = filenamewithpath + '_segmented' + '.h5'
-                hf = h5py.File(self.segmentname,'w')
-                hf.create_group('FOV0')
-                hf.close()
-    
-                self.predictname = filenamewithpath + '_predicted' + '.h5'
-                hf = h5py.File(self.predictname,'w')
-                hf.create_group('FOV0')
-                hf.close()
-
                 self.hdfpath = filenamewithpath + '.h5'
             
             
@@ -183,55 +153,12 @@ class Reader:
                     
         self.hdfpath = self.newhdfpath
         
-        templist = self.nd2path.split('/')        
         hf = h5py.File(self.hdfpath, 'w')
-        
         for i in range(0, self.Npos):
             grpname = self.fovlabels[i]
             hf.create_group(grpname)
         hf.close()
-        
-        
-        for k in range(0, len(templist)-1):
-            self.thresholdname = self.thresholdname+templist[k]+'/'
-        self.thresholdname = self.thresholdname + self.newhdfname + '_thresholded' + '.h5'
-        
-        hf = h5py.File(self.thresholdname,'w')
-        
-        for i in range(0, self.Npos):
-            
-            grpname = self.fovlabels[i]
-            hf.create_group(grpname)
-            
-        hf.close()
-        
-        
-        for k in range(0, len(templist)-1):
-            self.segmentname = self.segmentname+templist[k]+'/'
-        self.segmentname = self.segmentname + self.newhdfname + '_segmented' + '.h5'
-        
-        hf = h5py.File(self.segmentname,'w')
-        
-        for i in range(0, self.Npos):
-            
-            grpname = self.fovlabels[i]
-            hf.create_group(grpname)
-            
-        hf.close()
-
 
-        for k in range(0, len(templist)-1):
-            self.predictname = self.predictname+templist[k]+'/'
-        self.predictname = self.predictname + self.newhdfname + '_predicted' + '.h5'
-        
-        hf = h5py.File(self.predictname,'w')
-     
-        for i in range(0, self.Npos):
-     
-            grpname = self.fovlabels[i]
-            hf.create_group(grpname)
-            
-        hf.close()
 
     def LoadMask(self, currentT, currentFOV):
         """this method is called when one mask should be loaded from the file 
@@ -255,17 +182,32 @@ class Reader:
             return zeroarray
             
             
-    def TestTimeExist(self, currentT, currentFOV, file):
+    def TestTimeExist(self, currentT, currentFOV, file=None):
         """This method tests if the array which is requested by LoadMask
         already exists or not in the hdf file.
+        
+        If file is None, then it opens the h5py File. Otherwise allows to pass
+        an already open file. 
         """
+        def closefile(f):
+            if file is None:
+                f.close()
+                
+        def openfile(file):
+            if file is None:
+                return h5py.File(self.hdfpath, 'r+')
+            else:
+                return file
+                            
         if currentT <= len(self.tlabels) - 1 and currentT >= 0:
-            for t in file['/{}'.format(self.fovlabels[currentFOV])].keys():
+            f = openfile(file)
+            for t in f['/{}'.format(self.fovlabels[currentFOV])].keys():
                 # currentT is a number
                 # self.tlabels is some string that indexes the time point? E.g., T0?
                 if t == self.tlabels[currentT]:
+                    closefile(f)
                     return True
-        
+            closefile(f)
             return False
         else:
             return False
@@ -288,55 +230,11 @@ class Reader:
             dataset[:] = mask
             file.close()
             
-        else:
-            
-            file.create_dataset('/{}/{}'.format(self.fovlabels[currentFOV], self.tlabels[currentT]), data = mask, compression = 'gzip')
-            file.close()
-        
-        
-    def SaveThresholdMask(self, currentT, currentFOV, mask):
-        """This function is called when the user wants to save the mask in the
-        hdf5 file on the disk. It overwrites the existing array with the new 
-        one given in argument. 
-        If it is a new mask, there should already
-        be an existing null array which has been created by the LoadMask method
-        when the new array has been loaded/created in the main before calling
-        this save method.
-        """
-        
-        file = h5py.File(self.thresholdname, 'r+')
-        
-        if self.TestTimeExist(currentT,currentFOV,file):
-            dataset = file['/{}/{}'.format(self.fovlabels[currentFOV], self.tlabels[currentT])]
-            dataset[:] = mask
-            file.close()
         else:
             file.create_dataset('/{}/{}'.format(self.fovlabels[currentFOV], self.tlabels[currentT]), data = mask, compression = 'gzip')
             file.close()
         
-    def SaveSegMask(self, currentT, currentFOV, mask):
-        """This function is called when the user wants to save the mask in the
-        hdf5 file on the disk. It overwrites the existing array with the new 
-        one given in argument. 
-        If it is a new mask, there should already
-        be an existing null array which has been created by the LoadMask method
-        when the new array has been loaded/created in the main before calling
-        this save method.
-        """
-        
-        file = h5py.File(self.segmentname, 'r+')
         
-        if self.TestTimeExist(currentT,currentFOV,file):
-
-            dataset = file['/{}/{}'.format(self.fovlabels[currentFOV], self.tlabels[currentT])]
-            dataset[:] = mask
-            file.close()
-        else:
-            file.create_dataset('/{}/{}'.format(self.fovlabels[currentFOV], self.tlabels[currentT]), data = mask, compression = 'gzip')
-            file.close()
-    
-
-
     def TestIndexRange(self,currentT, currentfov):
         """this method receives the time and the fov index and checks
         if it is present in the images data.
@@ -353,7 +251,6 @@ class Reader:
         main program as an array. It fixes the fov index and iterates over the 
         time index.
         """
-        
         if not (currentT < self.sizet and currentfov < self.Npos):
             return None
         
@@ -380,130 +277,43 @@ class Reader:
             im = skimage.io.imread(self.nd2path + '/' + filelist[currentT])
             im = np.pad(im,( (0, self.sizey - im.shape[0]) , (0, self.sizex -  im.shape[1] ) ),constant_values=0) # pad with zeros so all images in the same folder have same size
             
-        # be careful here, the output is converted to 16, not sure it's a good idea.
         outputarray = np.array(im, dtype = np.uint16)
         return outputarray
 
-            
-    def LoadSeg(self, currentT, currentFOV):
-
-        file = h5py.File(self.segmentname, 'r+')
-        
-        if self.TestTimeExist(currentT,currentFOV,file):
-            mask = np.array(file['/{}/{}'.format(self.fovlabels[currentFOV], 
-                                                 self.tlabels[currentT])], 
-                            dtype = np.uint16)
-            file.close()
-            return mask
-            
-        else:
-
-            zeroarray = np.zeros([self.sizey, self.sizex],dtype = np.uint16)
-            file.create_dataset('/{}/{}'.format(self.fovlabels[currentFOV], 
-                                                self.tlabels[currentT]), 
-                                data = zeroarray, compression = 'gzip', 
-                                compression_opts = 7)
-            file.close()
-            return zeroarray
-        
-        
-    def LoadThreshold(self, currentT, currentFOV):
-        file = h5py.File(self.thresholdname, 'r+')
-        
-        if self.TestTimeExist(currentT,currentFOV,file):
-            mask = np.array(file['/{}/{}'.format(self.fovlabels[currentFOV], 
-                                                 self.tlabels[currentT])], 
-                            dtype = np.uint16)
-            file.close()            
-            return mask
-        
-        else:
-            zeroarray = np.zeros([self.sizey, self.sizex],dtype = np.uint16)
-            file.create_dataset('/{}/{}'.format(self.fovlabels[currentFOV], 
-                                                self.tlabels[currentT]), 
-                                data = zeroarray, compression = 'gzip', 
-                                compression_opts = 7)
-            file.close()
-            return zeroarray
-     
-        
-    def Segment(self, segparamvalue, currentT, currentFOV):
-        # Check if thresholded version exists
-        filethr = h5py.File(self.thresholdname, 'r+')
-        fileprediction = h5py.File(self.predictname,'r+')
-        
-        if (self.TestTimeExist(currentT, currentFOV, filethr) 
-            and self.TestTimeExist(currentT, currentFOV, fileprediction)):
-
-            tmpthrmask = np.array(filethr['/{}/{}'.format(self.fovlabels[currentFOV], 
-                                                          self.tlabels[currentT])])
-            pred = np.array(fileprediction['/{}/{}'.format(self.fovlabels[currentFOV], self.tlabels[currentT])])	
-            fileprediction.close()
-            segmentedmask = segment(tmpthrmask, pred, segparamvalue)	# SJR: added to read out the prediction as well
-            filethr.close()
-            return segmentedmask
-
-        else:
-            filethr.close()
-            return np.zeros([self.sizey,self.sizex], dtype = np.uint16)
-
-        
-    def ThresholdPred(self, thvalue, currentT, currentFOV):        
-        fileprediction = h5py.File(self.predictname,'r+')
-        if self.TestTimeExist(currentT, currentFOV, fileprediction):
-            
-            pred = np.array(fileprediction['/{}/{}'.format(self.fovlabels[currentFOV], 
-                                                           self.tlabels[currentT])])
-            fileprediction.close()
-            if thvalue == None:
-                thresholdedmask = nn.threshold(pred)
-            else:
-                thresholdedmask = nn.threshold(pred,thvalue)
-        
-            return thresholdedmask
-        else:
-            fileprediction.close()
-            return np.zeros([self.sizey, self.sizex], dtype = np.uint16)
-        
     
-    def TestPredExisting(self, currentT, currentFOV):
-        file = h5py.File(self.predictname, 'r+')
-        if self.TestTimeExist(currentT, currentFOV, file):
-            file.close()
-            return True
-        else:
-            file.close()
-            return False
-        
+    def LoadImageChannel(self,currentT, currentFOV, ch):
+        """Loads image at specified time, FOV and channel. Only for nd2 files"""
+        if self.isnd2:
+            with ND2Reader(self.nd2path) as images:
+                try:
+                    images.default_coords['v'] = currentFOV
+                except ValueError:
+                    pass
+                images.default_coords['t'] = currentT
+                images.iter_axes = 'c'
+                im = images[ch]
+                return np.array(im)
         
-    def LaunchPrediction(self, currentT, currentFOV):
-        """It launches the neural neutwork on the current image and creates 
-        an hdf file with the prediction for the time T and corresponding FOV. 
-        """
+        elif self.istiff:
+            return self.LoadOneImage(currentT, currentFOV)
+                
+        elif self.isfolder:
+            return self.LoadOneImage(currentT, currentFOV)
 
-        file = h5py.File(self.predictname, 'r+') 
-        if not self.TestTimeExist(currentT, currentFOV, file):
-            im = self.LoadOneImage(currentT, currentFOV)
-            im = skimage.exposure.equalize_adapthist(im)
-            im = im*1.0;	
-            pred = nn.prediction(im)
-            file.create_dataset('/{}/{}'.format(self.fovlabels[currentFOV], 
-                                self.tlabels[currentT]), data = pred, 
-                                compression = 'gzip', compression_opts = 7)
-        file.close()
-            
 
     def CellCorrespondance(self, currentT, currentFOV):
+        """Performs tracking, handles loading of the images. If the image to 
+        track has no precedent, returns unaltered mask. If no mask exists
+        for the current timeframe, returns zero array."""
         filemasks = h5py.File(self.hdfpath, 'r+')
-        fileseg = h5py.File(self.segmentname,'r+')
         
         if self.TestTimeExist(currentT-1, currentFOV, filemasks):
             prevmask = np.array(filemasks['/{}/{}'.format(self.fovlabels[currentFOV], 
                                                           self.tlabels[currentT-1])])
             # A mask exists for both time frames
-            if self.TestTimeExist(currentT, currentFOV, fileseg):
-                nextmask = np.array(fileseg['/{}/{}'.format(self.fovlabels[currentFOV],
-                                                            self.tlabels[currentT])])             
+            if self.TestTimeExist(currentT, currentFOV, filemasks):
+                nextmask = np.array(filemasks['/{}/{}'.format(self.fovlabels[currentFOV],
+                                                              self.tlabels[currentT])])             
                 newmask = hu.correspondance(prevmask, nextmask)
                 out = newmask
             # No mask exists for the current timeframe, return empty array
@@ -513,9 +323,9 @@ class Reader:
         
         else:
             # Current mask exists, but no previous - returns current mask unchanged
-            if self.TestTimeExist(currentT, currentFOV, fileseg):
-                nextmask = np.array(fileseg['/{}/{}'.format(self.fovlabels[currentFOV],
-                                                            self.tlabels[currentT])]) 
+            if self.TestTimeExist(currentT, currentFOV, filemasks):
+                nextmask = np.array(filemasks['/{}/{}'.format(self.fovlabels[currentFOV],
+                                                              self.tlabels[currentT])]) 
                 out = nextmask
             
             # Neither current nor previous mask exists - return empty array
@@ -524,27 +334,7 @@ class Reader:
                 out = null
                     
         filemasks.close()
-        fileseg.close()
         return out
-    
-        
-    def LoadImageChannel(self,currentT, currentFOV, ch):
-        if self.isnd2:
-            with ND2Reader(self.nd2path) as images:
-                try:
-                    images.default_coords['v'] = currentFOV
-                except ValueError:
-                    pass
-                images.default_coords['t'] = currentT
-                images.iter_axes = 'c'
-                im = images[ch]
-                return np.array(im)
-        
-        elif self.istiff:
-            return self.LoadOneImage(currentT, currentFOV)
-                
-        elif self.isfolder:
-            return self.LoadOneImage(currentT, currentFOV)
                 
                 
                 
diff --git a/init/InitButtons.py b/init/InitButtons.py
index d98a108559e9f82ffaacd0840327258060984ab6..2eb9c13dff09a118b1e7f69a0a0c91190d5f2328 100644
--- a/init/InitButtons.py
+++ b/init/InitButtons.py
@@ -155,25 +155,25 @@ def Init(parent):
     parent.button_changecellvalue.setStatusTip('Change value of one cell')
     parent.button_changecellvalue.setToolTip('Use left click to select one cell and enter a new value')
         
-    # THRESHOLD THE PREDICTION CHECKBOX
-    parent.button_threshold.setEnabled(False)
-    parent.button_threshold.stateChanged.connect(parent.ThresholdBoxCheck)
-    
-    # TEXT BOX FOR ENTERING THRESHOLD VALUE
-    parent.button_SetThreshold = QLineEdit()
-    parent.button_SetThreshold.setPlaceholderText('Enter a threshold value')
-    parent.button_SetThreshold.setValidator(QtGui.QDoubleValidator())
-    parent.button_SetThreshold.setMaximumWidth(150)
-    parent.button_SetThreshold.returnPressed.connect(parent.ThresholdPrediction)
-    parent.button_SetThreshold.setEnabled(False)
-    
-    # SAVE BUTTON FOR THE THRESHOLDED PREDICTION
-    parent.button_savethresholdmask = QPushButton('Save Threshold')
-    parent.button_savethresholdmask.toggle()
-    parent.button_savethresholdmask.setEnabled(False)
-    parent.button_savethresholdmask.clicked.connect(parent.ButtonSaveThresholdMask)
-    parent.button_savethresholdmask.setMaximumWidth(150)
-    parent.button_savethresholdmask.setStatusTip('Save the thresholded prediction')
+#    # THRESHOLD THE PREDICTION CHECKBOX
+#    parent.button_threshold.setEnabled(False)
+#    parent.button_threshold.stateChanged.connect(parent.ThresholdBoxCheck)
+    
+#    # TEXT BOX FOR ENTERING THRESHOLD VALUE
+#    parent.button_SetThreshold = QLineEdit()
+#    parent.button_SetThreshold.setPlaceholderText('Enter a threshold value')
+#    parent.button_SetThreshold.setValidator(QtGui.QDoubleValidator())
+#    parent.button_SetThreshold.setMaximumWidth(150)
+#    parent.button_SetThreshold.returnPressed.connect(parent.ThresholdPrediction)
+#    parent.button_SetThreshold.setEnabled(False)
+    
+#    # SAVE BUTTON FOR THE THRESHOLDED PREDICTION
+#    parent.button_savethresholdmask = QPushButton('Save Threshold')
+#    parent.button_savethresholdmask.toggle()
+#    parent.button_savethresholdmask.setEnabled(False)
+#    parent.button_savethresholdmask.clicked.connect(parent.ButtonSaveThresholdMask)
+#    parent.button_savethresholdmask.setMaximumWidth(150)
+#    parent.button_savethresholdmask.setStatusTip('Save the thresholded prediction')
     
     # SEGMENT THE OUTPUT OF THE THRESHOLD
     parent.button_segment.setEnabled(False)
diff --git a/init/InitLayout.py b/init/InitLayout.py
index 530909f5c5b77cb08066cc1729f80781e2caf1a7..7428f1fa3c68cb23e86d2e527de870b5e89b8d63 100644
--- a/init/InitLayout.py
+++ b/init/InitLayout.py
@@ -18,13 +18,13 @@ def Init(parent):
 #        LAYOUT FOR THE THRESHOLD BUTTONS
 #        all the buttons of the threshold function are placed in an horizontal 
 #        stack
-        hbox_threshold = QtWidgets.QHBoxLayout()
-        hbox_threshold.addWidget(parent.button_threshold)
-        hbox_threshold.addWidget(parent.button_SetThreshold)
-        hbox_threshold.addWidget(parent.button_savethresholdmask)
-#        if this line is not put, then the buttons are placed along the whole
-#        length of the window, in this way they are all grouped to the left.
-        hbox_threshold.addStretch(1)       
+#        hbox_threshold = QtWidgets.QHBoxLayout()
+#        hbox_threshold.addWidget(parent.button_threshold)
+#        hbox_threshold.addWidget(parent.button_SetThreshold)
+#        hbox_threshold.addWidget(parent.button_savethresholdmask)
+##        if this line is not put, then the buttons are placed along the whole
+##        length of the window, in this way they are all grouped to the left.
+#        hbox_threshold.addStretch(1)       
       
         
         
diff --git a/misc/PlotCanvas.py b/misc/PlotCanvas.py
index 3b9eb2b9505caa4ae53d8e841a85363c4f173257..801bd2c072ebff24b1383c5cfd8a8c57a9a2ab27 100644
--- a/misc/PlotCanvas.py
+++ b/misc/PlotCanvas.py
@@ -1,9 +1,8 @@
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 """
-Created on Mon May 11 17:29:47 2020
-
-@author: myfiles
+This file handles the PlotCanvas of the GUI - aka the area where the graphics 
+are shown. 
 """
 
 import numpy as np
@@ -22,6 +21,9 @@ from matplotlib.path import Path
 
 
 class PlotCanvas(FigureCanvas):
+    
+    
+    
     def __init__(self, parent=None):
         """this class defines the canvas. It initializes a figure, which is then
         used to plot our data using imshow.
@@ -30,12 +32,6 @@ class PlotCanvas(FigureCanvas):
         # time index.
         fig, (self.ax2, self.ax, self.ax3) = plt.subplots(1,3, sharex = True, sharey = True)
         
-        # self.ax2.axis('tight')
-        # self.ax.axis('tight')
-        # self.ax3.axis('tight')
-        
-        # plt.gca().xaxis.set_major_locator(plt.NullLocator())
-        # plt.gca().yaxis.set_major_locator(plt.NullLocator())
         fig.subplots_adjust(bottom=0, top=1, left=0, right=1, wspace = 0.05, hspace = 0.05)
         FigureCanvas.__init__(self, fig)
         self.setParent(parent)
@@ -48,7 +44,6 @@ class PlotCanvas(FigureCanvas):
         
         # the self.currpicture attribute takes the original data and will then 
         # contain the updates drawn by the user.
-        
         self.currpicture = parent.currentframe
         self.prevpicture = parent.previousframe
         self.nextpicture = parent.nextframe
@@ -58,14 +53,11 @@ class PlotCanvas(FigureCanvas):
         self.tempmask = self.plotmask.copy()
         self.tempplotmask = self.plotmask.copy()
         
-        self.ThresholdMask = np.zeros([parent.reader.sizey, parent.reader.sizex], dtype = np.uint16)
-        self.SegmentedMask = np.zeros([parent.reader.sizey, parent.reader.sizex], dtype = np.uint16)
-        
         # this line is just here to not attribute a zero value to the plot
         # because if so, then it does not update the plot and it stays blank.
-        # (it is unclear why..if someone finds a better solution)
         self.prevpicture = self.currpicture.copy()
         
+        # Initialize Plots
         self.currplot, self.currmask = self.plot(self.currpicture, self.plotmask, self.ax)
         
         self.previousplot, self.previousmask = self.plot(self.prevpicture, self.prevplotmask, self.ax2)
@@ -73,7 +65,6 @@ class PlotCanvas(FigureCanvas):
         self.prevplotmask = np.zeros([parent.reader.sizey, parent.reader.sizex], dtype =np.uint16)
         
         self.nextplot, self.nextmask = self.plot(self.nextpicture, self.nextplotmask, self.ax3)
-        
         self.previousplot.set_data(self.prevpicture)
         self.previousmask.set_data((self.prevplotmask%10+1)*(self.prevplotmask != 0))
 
@@ -82,6 +73,7 @@ class PlotCanvas(FigureCanvas):
         self.update()
         self.flush_events()
         
+        # Set title labels
         self.titlecurr = self.ax.set_title('Time index {}'.format(parent.Tindex))
         self.titleprev = self.ax2.set_title('No frame {}'.format(''))
         self.titlenext = self.ax3.set_title('Next time index {}'.format(parent.Tindex+1))
diff --git a/unet/segment.py b/unet/segment.py
index 7176e0e7d4b9701057fe807f6406fecc99c8f319..3d873879801345f2b60ddc3d14394aacec51c410 100644
--- a/unet/segment.py
+++ b/unet/segment.py
@@ -19,7 +19,6 @@ def segment(th, pred, min_distance=10, topology=None):
     """
     dtr = ndi.morphology.distance_transform_edt(th)
     if topology is None:
-        print('topology is none')
         topology = -dtr
     elif callable(topology):
         topology = topology(dtr)