Index: sansview/perspectives/fitting/basepage.py
===================================================================
--- sansview/perspectives/fitting/basepage.py	(revision 3cd5806375c406cd55c809b2efb82cc2de2531de)
+++ sansview/perspectives/fitting/basepage.py	(revision 90a7bbd9e20cfbcdbcd72d6d1e3b0391cb2fe486)
@@ -175,5 +175,4 @@
         """
         """
-        print "fitting panel", self.window_name
         if self._manager is not None:
             wx.PostEvent(self._manager.parent, PanelOnFocusEvent(panel=self))
@@ -380,5 +379,4 @@
         
         """
-        print "manager", manager
         self._manager = manager  
         self.state.manager = manager
Index: sansview/perspectives/fitting/fitpage.py
===================================================================
--- sansview/perspectives/fitting/fitpage.py	(revision 13913ec86b13f57db7208e53a043421a6efe2f78)
+++ sansview/perspectives/fitting/fitpage.py	(revision 90a7bbd9e20cfbcdbcd72d6d1e3b0391cb2fe486)
@@ -796,5 +796,5 @@
             msg="Please select a Model first..."
             wx.MessageBox(msg, 'Info')
-            wx.PostEvent(self.manager.parent, StatusEvent(status=\
+            wx.PostEvent(self._manager.parent, StatusEvent(status=\
                             "Fit: %s"%msg))
             return
@@ -821,11 +821,11 @@
         self.qmin_x = float(self.qmin.GetValue())
         self.qmax_x = float( self.qmax.GetValue())
-        self.manager._reset_schedule_problem( value=0)
-        self.manager.schedule_for_fit( value=1,page=self,fitproblem =None) 
-        self.manager.set_fit_range(page= self,qmin= self.qmin_x, 
+        self._manager._reset_schedule_problem( value=0)
+        self._manager.schedule_for_fit( value=1,page=self,fitproblem =None) 
+        self._manager.set_fit_range(page= self,qmin= self.qmin_x, 
                                    qmax= self.qmax_x)
         
         #single fit 
-        self.manager.onFit()
+        self._manager.onFit()
         ## allow stopping the fit 
         #if self.engine_type=="scipy":
@@ -845,5 +845,5 @@
         self.btFit.SetLabel("Fit")
         if self.engine_type=="scipy":
-            self.manager.stop_fit()
+            self._manager.stop_fit()
         self.btFit.Unbind(event=wx.EVT_BUTTON, id=self.btFit.GetId())
         self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit,
@@ -900,5 +900,5 @@
                  evt = ModelEventbox(model = self.model)
           
-            self.manager._on_model_panel(evt = evt)
+            self._manager._on_model_panel(evt = evt)
             self.state.model = self.model.clone()
             self.state.model.name = self.model.name
@@ -919,5 +919,5 @@
             msg="Please select a Model first..."
             wx.MessageBox(msg, 'Info')
-            #wx.PostEvent(self.manager.parent, StatusEvent(status=\
+            #wx.PostEvent(self._manager.parent, StatusEvent(status=\
             #                "Parameters: %s"%msg))
             return
@@ -928,5 +928,5 @@
         #get event object
         tcrtl= event.GetEventObject()
-        wx.PostEvent(self.manager.parent, StatusEvent(status=" \
+        wx.PostEvent(self._manager.parent, StatusEvent(status=" \
                                 updating ... ",type="update"))
         #Clear msg if previously shown.
@@ -950,5 +950,5 @@
                         flag = flag or flag1
                 elif self.data.__class__.__name__ !="Data2D":
-                    self.manager.set_smearer(smearer=temp_smearer, 
+                    self._manager.set_smearer(smearer=temp_smearer, 
                                              qmin= float(self.qmin_x),
                                             qmax= float(self.qmax_x)) 
@@ -1434,5 +1434,5 @@
    
         if self.engine_type != None:
-            self.manager._on_change_engine(engine=self.engine_type)
+            self._manager._on_change_engine(engine=self.engine_type)
 
         self.select_param(event = None) 
@@ -1623,5 +1623,5 @@
         #PostStatusEvent     
         msg = "Fit completed! "
-        wx.PostEvent(self.manager.parent, StatusEvent(status=msg))
+        wx.PostEvent(self._manager.parent, StatusEvent(status=msg))
 
     def onPinholeSmear(self, event):
@@ -1641,5 +1641,5 @@
             msg="Please select a Model first..."
             wx.MessageBox(msg, 'Info')
-            wx.PostEvent(self.manager.parent, StatusEvent(status=\
+            wx.PostEvent(self._manager.parent, StatusEvent(status=\
                             "Smear: %s"%msg))
             return
@@ -1776,10 +1776,10 @@
 
         if msg != None:
-            wx.PostEvent(self.manager.parent, StatusEvent(status = msg ))
+            wx.PostEvent(self._manager.parent, StatusEvent(status = msg ))
         else:
             get_pin_min.SetBackgroundColour("white")
             get_pin_max.SetBackgroundColour("white")
         ## set smearing value whether or not the data contain the smearing info
-        self.manager.set_smearer(smearer=self.current_smearer, qmin= \
+        self._manager.set_smearer(smearer=self.current_smearer, qmin= \
                                  float(self.qmin_x),qmax= float(self.qmax_x))
         return msg
@@ -1820,5 +1820,5 @@
             msg="Please select a Model first..."
             wx.MessageBox(msg, 'Info')
-            wx.PostEvent(self.manager.parent, StatusEvent(status=\
+            wx.PostEvent(self._manager.parent, StatusEvent(status=\
                             "Smear: %s"%msg))
             return
@@ -1862,5 +1862,5 @@
         wx.PostEvent(self.parent, event)
         if msg != None:
-            wx.PostEvent(self.manager.parent, StatusEvent(status = msg))
+            wx.PostEvent(self._manager.parent, StatusEvent(status = msg))
 
     def _is_changed_slit(self):  
@@ -1951,5 +1951,5 @@
         #temp_smearer = self.current_smearer
         ## set smearing value whether or not the data contain the smearing info
-        self.manager.set_smearer(smearer=self.current_smearer, qmin= \
+        self._manager.set_smearer(smearer=self.current_smearer, qmin= \
                                  float(self.qmin_x), qmax= float(self.qmax_x)) 
         return msg
@@ -1989,5 +1989,5 @@
             msg="Please select a Model first..."
             wx.MessageBox(msg, 'Info')
-            wx.PostEvent(self.manager.parent, StatusEvent(status=\
+            wx.PostEvent(self._manager.parent, StatusEvent(status=\
                             "Smear: %s"%msg))
             return
@@ -2018,8 +2018,8 @@
                 msg= ": Slit smearing parameters"
             if self.smearer ==None:
-                wx.PostEvent(self.manager.parent, StatusEvent(status=\
+                wx.PostEvent(self._manager.parent, StatusEvent(status=\
                             "Data contains no smearing information"))
             else:
-                wx.PostEvent(self.manager.parent, StatusEvent(status=\
+                wx.PostEvent(self._manager.parent, StatusEvent(status=\
                             "Data contains smearing information"))
 
@@ -2036,5 +2036,5 @@
         self.Layout()
         ## set smearing value whether or not the data contain the smearing info
-        self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x),
+        self._manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x),
                                      qmax= float(self.qmax_x)) 
 
@@ -2185,6 +2185,6 @@
             return
         ## the panel is drawn using the current value of the fit engine
-        if self.engine_type==None and self.manager !=None:
-            self.engine_type= self.manager._return_engine_type()
+        if self.engine_type==None and self._manager !=None:
+            self.engine_type= self._manager._return_engine_type()
 
         box_description= wx.StaticBox(self, -1,str("Model Parameters"))
Index: sansview/perspectives/fitting/fitpanel.py
===================================================================
--- sansview/perspectives/fitting/fitpanel.py	(revision 3cd5806375c406cd55c809b2efb82cc2de2531de)
+++ sansview/perspectives/fitting/fitpanel.py	(revision 90a7bbd9e20cfbcdbcd72d6d1e3b0391cb2fe486)
@@ -11,106 +11,4 @@
 _BOX_WIDTH = 80
 
-
-class StateIterator(object):
-    """
-    Contains all saved state of a given page.
-    Provide position of the current state of a page, the first save state
-    and the last state for a given page. 
-    Allow easy undo or redo for a given page  
-    """
-    def __init__(self):
-        """
-        """
-        self._current=0
-       
-    def __iter__(self):
-        """
-        """
-        return self
-    
-    def first(self):
-        """
-        """
-        self._current =0
-        return self._current
-    
-    def next(self, max ):
-        """
-        """
-        if self._current < max:
-            self._current += 1
-        return self._current
-    
-    def previous(self):
-        """
-        """
-        if self._current > 0:
-            self._current = self._current -1
-        return self._current
-    
-    def currentPosition(self):
-        """
-        """
-        return self._current
-    
-    def setPosition(self, value):
-        """
-        """
-        if value >=0:
-            self._current = int(value)
-        
-    
-class ListOfState(list):    
-    """
-    """ 
-    def __init__(self, *args, **kw):
-        list.__init__(self, *args, **kw)
-        self.iterator = StateIterator()
-        
-    def appendItem(self, x):
-        """
-        """
-        self.append(x)
-        self.iterator.setPosition(value= len(self)-1)
-        
-    def removeItem(self, x):
-        """
-        """
-        self.iterator.previous()
-        self.remove(x)
-        
-    def getPreviousItem(self):
-        """
-        """
-        position = self.iterator.previous()
-        
-        if position < 0:
-            return None
-        else:
-            return self[position]
-        
-    def getNextItem(self):
-        """
-        """
-        position = self.iterator.next(max= len(self)-1)
-        if position >= len(self):
-            return None
-        else:
-            return self[position]
-        
-    def getCurrentItem(self):
-        """
-        """
-        postion = self.iterator.currentPosition()
-        if postion >= 0 and position < len(self):
-            return self[postion]
-        else:
-            return None
-        
-    def getCurrentPosition(self):
-        """
-        """
-        return self.iterator.currentPosition()
-          
 
 class PageInfo(object):
@@ -189,4 +87,5 @@
         self.Bind(basepage.EVT_PREVIOUS_STATE, self._onUndo)
         self.Bind(basepage.EVT_NEXT_STATE, self._onRedo)
+        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.on_page_changing)
        
         #add default pages
@@ -199,11 +98,16 @@
         self.Center()
         
+    def on_page_changing(self, event):
+        pos = self.GetSelection()
+        if pos != -1:
+            selected_page = self.GetPage(pos)
+            wx.PostEvent(self.parent, PanelOnFocusEvent(panel=selected_page))
     def on_set_focus(self, event):
         """
         """
         pos = self.GetSelection()
-        selected_page = self.GetPage(pos)
-        print "panel on fogus", selected_page.window_name
-        wx.PostEvent(self.parent, PanelOnFocusEvent(panel=selected_page))
+        if pos != -1:
+            selected_page = self.GetPage(pos)
+            wx.PostEvent(self.parent, PanelOnFocusEvent(panel=selected_page))
         
     def get_data(self):
@@ -212,6 +116,7 @@
         """
         pos = self.GetSelection()
-        selected_page = self.GetPage(pos)
-        return selected_page.get_data()
+        if pos != -1:
+            selected_page = self.GetPage(pos)
+            return selected_page.get_data()
     
     def get_state(self):
@@ -220,6 +125,7 @@
         """
         pos = self.GetSelection()
-        selected_page = self.GetPage(pos)
-        return selected_page.get_state()
+        if pos != -1:
+            selected_page = self.GetPage(pos)
+            return selected_page.get_state()
     
     def add_default_pages(self):
@@ -240,4 +146,5 @@
         remove all pages, used when a svs file is opened
         """
+        
         #get number of pages
         nop = self.GetPageCount()
@@ -246,7 +153,10 @@
             #delete the first page until no page exists
             page = self.GetPage(0)
+            if self._manager.parent.panel_on_focus == page:
+                self._manager.parent.panel_on_focus = None
             self._close_helper(selected_page=page)
             self.DeletePage(0)
             nop = nop - 1
+            
         ## save the title of the last page tab added
         self.fit_page_name = {}
@@ -276,12 +186,13 @@
                     panel.save_current_state()
                     
-    def clear_panel(self, format='.svs'):
+    def clear_panel(self):
         """
         Clear and close all panels, used by guimanager
         """
-        if format == '.svs':
-            #close all panels only when svs file opened
-            self.close_all()
-            self._manager.mypanels = []
+       
+        #close all panels only when svs file opened
+        self.close_all()
+        self._manager.mypanels = []
+        
                        
     def on_close_page(self, event=None):
Index: sansview/perspectives/fitting/fitting.py
===================================================================
--- sansview/perspectives/fitting/fitting.py	(revision 75fbd1798f95ec58502a817f7435b1dfae03b69f)
+++ sansview/perspectives/fitting/fitting.py	(revision 90a7bbd9e20cfbcdbcd72d6d1e3b0391cb2fe486)
@@ -35,8 +35,6 @@
 from sans.guiframe.events import ERR_DATA
 from sans.guiframe.events import EVT_SLICER_PARS_UPDATE
-from sans.guiframe.events import EVT_FITSTATE_UPDATE
-
-#from sans.fit.AbstractFitEngine import Model
-#from sans.fit.AbstractFitEngine import FitAbort
+
+
 from .console import ConsoleUpdate
 from .fitproblem import FitProblem
@@ -263,4 +261,9 @@
         return self.mypanels
     
+    def clear_panel(self):
+        """
+        """
+        self.fit_panel.clear_panel(format=format)
+        
     def set_default_perspective(self):
         """
@@ -297,5 +300,5 @@
         : param datainfo: data
         """
-        state = self.state_reader.get_state()
+        #state = self.state_reader.get_state()
         if state != None:
             # store fitting state in temp_state
Index: sansview/perspectives/fitting/pagestate.py
===================================================================
--- sansview/perspectives/fitting/pagestate.py	(revision 75fbd1798f95ec58502a817f7435b1dfae03b69f)
+++ sansview/perspectives/fitting/pagestate.py	(revision 90a7bbd9e20cfbcdbcd72d6d1e3b0391cb2fe486)
@@ -1173,5 +1173,5 @@
                     state.data.group_id = name
                     #store state in fitting
-                    #self.call_back(state=state, datainfo=output[ind],format=ext)
+                    self.call_back(state=state, datainfo=output[ind],format=ext)
                     self.state= state
                 return output
