Index: src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py
===================================================================
--- src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py	(revision 5236449e83a334d07863f099c063375d8b54b4c2)
+++ src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py	(revision cbcdd2c5b8d12554dc14f421d4dd36716db47864)
@@ -12,5 +12,4 @@
     """
     """
-    updateTheoryFromPerspectiveSignal =  QtCore.pyqtSignal(QtGui.QStandardItem)
     name = "Fitting" # For displaying in the combo box in DataExplorer
     def __init__(self, manager=None, parent=None, data=None):
@@ -44,5 +43,6 @@
         self.setWindowTitle('Fit panel - Active Fitting Optimizer: %s' % self.optimizer)
 
-        self.communicate = GuiUtils.Communicate()
+        #self.communicate = GuiUtils.Communicate()
+        self.communicate = self.parent.communicator()
 
     def addFit(self, data):
@@ -54,5 +54,4 @@
         self.maxIndex += 1
         self.addTab(tab, self.tabName())
-        tab.signalTheory.connect(self.passSignal)
 
     def tabName(self):
@@ -67,5 +66,5 @@
         Update local bookkeeping on tab close
         """
-        assert(len(self.tabs) >= index)
+        assert len(self.tabs) >= index
         # don't remove the last tab
         if len(self.tabs) <= 1:
@@ -86,5 +85,5 @@
         Pass it over to the calculator
         """
-        assert(data_item is not None)
+        assert data_item is not None
 
         if not isinstance(data_item, list):
@@ -98,12 +97,7 @@
         self._model_item = data_item[0]
 
-        # Extract data on 1st child - this is the Data1D/2D component
-        data = GuiUtils.dataFromItem(self._model_item)
-
-        # self.model.item(WIDGETS.W_FILENAME).setData(QtCore.QVariant(self._model_item.text()))
-
         # Find the first unassigned tab.
         # If none, open a new tab.
-        available_tabs = list(map(lambda tab:tab.acceptsData(), self.tabs))
+        available_tabs = list(map(lambda tab: tab.acceptsData(), self.tabs))
 
         if numpy.any(available_tabs):
@@ -111,14 +105,2 @@
         else:
             self.addFit(data_item)
-
-
-    def passSignal(self, theory_item):
-        """
-        """
-        self.updateTheoryFromPerspectiveSignal.emit(theory_item)
-
-if __name__ == "__main__":
-    app = QtGui.QApplication([])
-    dlg = FittingWindow()
-    dlg.show()
-    sys.exit(app.exec_())
Index: src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
===================================================================
--- src/sas/qtgui/Perspectives/Fitting/FittingWidget.py	(revision 5236449e83a334d07863f099c063375d8b54b4c2)
+++ src/sas/qtgui/Perspectives/Fitting/FittingWidget.py	(revision cbcdd2c5b8d12554dc14f421d4dd36716db47864)
@@ -7,5 +7,5 @@
 import logging
 import traceback
-
+from twisted.internet import threads
 
 from PyQt4 import QtGui
@@ -23,4 +23,5 @@
 from sas.sascalc.dataloader.data_info import Source
 from sas.sasgui.perspectives.fitting.model_thread import Calc1D
+from sas.sasgui.perspectives.fitting.model_thread import Calc2D
 
 from UI.FittingWidgetUI import Ui_FittingWidgetUI
@@ -28,5 +29,8 @@
 TAB_MAGNETISM = 4
 TAB_POLY = 3
-CATEGORY_DEFAULT="Choose category..."
+CATEGORY_DEFAULT = "Choose category..."
+QMIN_DEFAULT = 0.0005
+QMAX_DEFAULT = 0.5
+NPTS_DEFAULT = 50
 
 class FittingWidget(QtGui.QWidget, Ui_FittingWidgetUI):
@@ -34,6 +38,4 @@
     Main widget for selecting form and structure factor models
     """
-    signalTheory =  QtCore.pyqtSignal(QtGui.QStandardItem)
-
     def __init__(self, manager=None, parent=None, data=None, id=1):
         """
@@ -46,12 +48,20 @@
 
         # Necessary globals
+        self.parent = parent
+        # SasModel is loaded
         self.model_is_loaded = False
+        # Data[12]D passed and set
         self.data_is_loaded = False
+        # Current SasModel in view
         self.kernel_module = None
+        # Current SasModel view dimension
         self.is2D = False
+        # Current SasModel is multishell
         self.model_has_shells = False
+        # Utility variable to enable unselectable option in category combobox
         self._previous_category_index = 0
+        # Utility variable for multishell display
         self._last_model_row = 0
-        self._current_parameter_name = None
+        # Dictionary of {model name: model class} for the current category
         self.models = {}
 
@@ -60,7 +70,8 @@
 
         # Parameters
-        self.q_range_min = 0.0005
-        self.q_range_max = 0.5
-        self.npts = 20
+        self.q_range_min = QMIN_DEFAULT
+        self.q_range_max = QMAX_DEFAULT
+        self.npts = NPTS_DEFAULT
+        # Main Data[12]D holder
         self._data = None
 
@@ -68,5 +79,5 @@
         self.setupUi(self)
         self.setWindowTitle("Fitting")
-        self.communicate = GuiUtils.Communicate()
+        self.communicate = self.parent.communicate
 
         # Set the main models
@@ -74,6 +85,4 @@
         self._poly_model = QtGui.QStandardItemModel()
         self._magnet_model = QtGui.QStandardItemModel()
-        # Proxy model for custom views on the main _model_model
-        self.proxyModel = QtGui.QSortFilterProxyModel()
 
         # Param model displayed in param list
@@ -124,7 +133,10 @@
     def data(self, value):
         """ data setter """
+        # _index contains the QIndex with data
         self._index = value
+        # _data contains the actual Data[12]D
         self._data = GuiUtils.dataFromItem(value[0])
         self.data_is_loaded = True
+        # Tag along functionality
         self.updateQRange()
         self.cmdFit.setEnabled(True)
@@ -135,16 +147,20 @@
 
     def disableModelCombo(self):
+        """ Disable the combobox """
         self.cbModel.setEnabled(False)
         self.label_3.setEnabled(False)
 
     def enableModelCombo(self):
+        """ Enable the combobox """
         self.cbModel.setEnabled(True)
         self.label_3.setEnabled(True)
 
     def disableStructureCombo(self):
+        """ Disable the combobox """
         self.cbStructureFactor.setEnabled(False)
         self.label_4.setEnabled(False)
 
     def enableStructureCombo(self):
+        """ Enable the combobox """
         self.cbStructureFactor.setEnabled(True)
         self.label_4.setEnabled(True)
@@ -156,8 +172,8 @@
         if self.data_is_loaded:
             self.q_range_min, self.q_range_max, self.npts = self.computeDataRange(self.data)
-        # set Q range labels
+        # set Q range labels on the main tab
         self.lblMinRangeDef.setText(str(self.q_range_min))
         self.lblMaxRangeDef.setText(str(self.q_range_max))
-
+        # set Q range labels on the options tab
         self.txtMaxRange.setText(str(self.q_range_max))
         self.txtMinRange.setText(str(self.q_range_min))
@@ -176,9 +192,8 @@
         self.chkMagnetism.setEnabled(False)
         self.chkMagnetism.setCheckState(False)
-        # tabs
+        # Tabs
         self.tabFitting.setTabEnabled(TAB_POLY, False)
         self.tabFitting.setTabEnabled(TAB_MAGNETISM, False)
         self.lblChi2Value.setText("---")
-    
         # Update Q Ranges
         self.updateQRange()
@@ -188,14 +203,27 @@
         Connect GUI element signals
         """
+        # Comboboxes
         self.cbStructureFactor.currentIndexChanged.connect(self.selectStructureFactor)
         self.cbCategory.currentIndexChanged.connect(self.selectCategory)
         self.cbModel.currentIndexChanged.connect(self.selectModel)
+        # Checkboxes
         self.chk2DView.toggled.connect(self.toggle2D)
         self.chkPolydispersity.toggled.connect(self.togglePoly)
         self.chkMagnetism.toggled.connect(self.toggleMagnetism)
+        # Buttons
         self.cmdFit.clicked.connect(self.onFit)
+        self.cmdPlot.clicked.connect(self.onPlot)
+        # Line edits
+        self.txtNpts.textChanged.connect(self.onNpts)
+        self.txtMinRange.textChanged.connect(self.onMinRange)
+        self.txtMaxRange.textChanged.connect(self.onMaxRange)
+
+        # Respond to change in parameters from the UI
+        self._model_model.itemChanged.connect(self.updateParamsFromModel)
 
     def setDefaultStructureCombo(self):
-        # Fill in the structure factors combo box with defaults
+        """
+        Fill in the structure factors combo box with defaults
+        """
         structure_factor_list = self.master_category_dict.pop('Structure Factor')
         structure_factors = []
@@ -208,5 +236,4 @@
         """
         Select Category from list
-        :return:
         """
         category = self.cbCategory.currentText()
@@ -224,4 +251,5 @@
             return
 
+        # Safely clear and enable the model combo
         self.cbModel.blockSignals(True)
         self.cbModel.clear()
@@ -231,6 +259,8 @@
 
         self._previous_category_index = self.cbCategory.currentIndex()
+        # Retrieve the list of models
         model_list = self.master_category_dict[str(category)]
         models = []
+        # Populate the models combobox
         for (model, _) in model_list:
             models.append(model)
@@ -241,6 +271,5 @@
         Respond to select Model from list event
         """
-        model = self.cbModel.currentText()
-        self._current_parameter_name = model
+        model = str(self.cbModel.currentText())
 
         # SasModel -> QModel
@@ -248,21 +277,24 @@
 
         if self._index is None:
+            # Create default datasets if no data passed
             if self.is2D:
                 self.createDefault2dData()
             else:
                 self.createDefault1dData()
-            self.createTheoryIndex()
+            # DESIGN: create the theory now or on Plot event?
+            #self.createTheoryIndex()
         else:
-            # TODO: 2D case
+            # Create datasets and errorbars for current data
+            if self.is2D:
+                self.calculate2DForModel()
+            else:
+                self.calculate1DForModel()
             # TODO: attach the chart to index
-            self.calculate1DForModel()
 
     def selectStructureFactor(self):
         """
         Select Structure Factor from list
-        :param:
-        :return:
-        """
-        model = self.cbStructureFactor.currentText()
+        """
+        model = str(self.cbStructureFactor.currentText())
         self.setModelModel(model)
 
@@ -275,17 +307,10 @@
         self.model_enabled_dict = defaultdict(bool)
 
-        try:
-            categorization_file = CategoryInstaller.get_user_file()
-            if not os.path.isfile(categorization_file):
-                categorization_file = CategoryInstaller.get_default_file()
-            cat_file = open(categorization_file, 'rb')
+        categorization_file = CategoryInstaller.get_user_file()
+        if not os.path.isfile(categorization_file):
+            categorization_file = CategoryInstaller.get_default_file()
+        with open(categorization_file, 'rb') as cat_file:
             self.master_category_dict = json.load(cat_file)
             self.regenerateModelDict()
-            cat_file.close()
-        except IOError:
-            raise
-            print 'Problem reading in category file.'
-            print 'We even looked for it, made sure it was there.'
-            print 'An existential crisis if there ever was one.'
 
         # Load the model dict
@@ -296,5 +321,5 @@
     def regenerateModelDict(self):
         """
-        regenerates self.by_model_dict which has each model name as the
+        Regenerates self.by_model_dict which has each model name as the
         key and the list of categories belonging to that model
         along with the enabled mapping
@@ -310,7 +335,5 @@
         Returns a list of all multi-shell parameters in 'model'
         """
-        iter_params = list(filter(lambda par: "[" in par.name, model.iq_parameters))
-
-        return iter_params
+        return list(filter(lambda par: "[" in par.name, model.iq_parameters))
 
     def getMultiplicity(self, model):
@@ -333,6 +356,5 @@
         Adds background parameter with default values to the model
         """
-        assert(isinstance(model, QtGui.QStandardItemModel))
-
+        assert isinstance(model, QtGui.QStandardItemModel)
         checked_list = ['background', '0.001', '-inf', 'inf', '1/cm']
         self.addCheckedListToModel(model, checked_list)
@@ -342,11 +364,10 @@
         Adds scale parameter with default values to the model
         """
-        assert(isinstance(model, QtGui.QStandardItemModel))
-
+        assert isinstance(model, QtGui.QStandardItemModel)
         checked_list = ['scale', '1.0', '0.0', 'inf', '']
         self.addCheckedListToModel(model, checked_list)
 
     def addCheckedListToModel(self, model, param_list):
-        assert(isinstance(model, QtGui.QStandardItemModel))
+        assert isinstance(model, QtGui.QStandardItemModel)
         item_list = [QtGui.QStandardItem(item) for item in param_list]
         item_list[0].setCheckable(True)
@@ -377,17 +398,15 @@
     def setModelModel(self, model_name):
         """
-        Setting model parameters into table based on selected
-        :param model_name:
-        """
+        Setting model parameters into table based on selected category
+        """
+        assert isinstance(model_name, str)
+
         # Crete/overwrite model items
         self._model_model.clear()
-        model_name = str(model_name)
 
         kernel_module = generate.load_kernel_module(model_name)
-        #model_info = modelinfo.make_model_info(kernel_module)
-        #self.kernel_module = _make_model_from_info(model_info)
         self.model_parameters = modelinfo.make_parameter_table(getattr(kernel_module, 'parameters', []))
 
-        # Instantiate the current model
+        # Instantiate the current sasmodel
         self.kernel_module = self.models[model_name]()
 
@@ -413,11 +432,31 @@
         self.updateQRange()
 
+    def updateParamsFromModel(self, item):
+        """
+        Callback method for updating the sasmodel parameters with the GUI values
+        """
+        # Extract changed value. Assumes proper validation by QValidator/Delegate
+        value = float(item.text())
+        model_column = item.column()
+        model_row = item.row()
+        name_index = self._model_model.index(model_row, 0)
+        parameter_name = str(self._model_model.data(name_index).toPyObject()) # sld, background etc.
+        property_name = str(self._model_model.headerData(1, model_column).toPyObject()) # Value, min, max, etc.
+
+        print "%s(%s) => %d" % (parameter_name, property_name, value)
+        self.kernel_module.params[parameter_name] = value
+
+        # min/max to be changed in self.kernel_module.details[parameter_name] = ['Ang', 0.0, inf]
+
+        # magnetic params in self.kernel_module.details['M0:parameter_name'] = value
+        # multishell params in self.kernel_module.details[??] = value
+
     def computeDataRange(self, data):
         """
-        compute the minimum and the maximum range of the data
+        Compute the minimum and the maximum range of the data
         return the npts contains in data
         """
-        assert(data is not None)
-        assert((isinstance(data, Data1D) or isinstance(data, Data2D)))
+        assert data is not None
+        assert (isinstance(data, Data1D) or isinstance(data, Data2D))
         qmin, qmax, npts = None, None, None
         if isinstance(data, Data1D):
@@ -426,5 +465,5 @@
                 qmax = max(data.x)
                 npts = len(data.x)
-            except:
+            except (ValueError, TypeError):
                 msg = "Unable to find min/max/length of \n data named %s" % \
                             data.filename
@@ -436,9 +475,9 @@
                 x = max(numpy.fabs(data.xmin), numpy.fabs(data.xmax))
                 y = max(numpy.fabs(data.ymin), numpy.fabs(data.ymax))
-            except:
+            except (ValueError, TypeError):
                 msg = "Unable to find min/max of \n data named %s" % \
                             data.filename
                 raise ValueError, msg
-            qmax = math.sqrt(x * x + y * y)
+            qmax = numpy.sqrt(x * x + y * y)
             npts = len(data.data)
         return qmin, qmax, npts
@@ -470,15 +509,19 @@
                 # Find param in volume_params
                 for p in parameters.form_volume_parameters:
-                    if p.name == param.name:
-                        item1_2 = QtGui.QStandardItem(str(p.default))
-                        item1_3 = QtGui.QStandardItem(str(p.limits[0]))
-                        item1_4 = QtGui.QStandardItem(str(p.limits[1]))
-                        item1_5 = QtGui.QStandardItem(p.units)
-                        poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5])
-                        break
-
+                    if p.name != param.name:
+                        continue
+                    item1_2 = QtGui.QStandardItem(str(p.default))
+                    item1_3 = QtGui.QStandardItem(str(p.limits[0]))
+                    item1_4 = QtGui.QStandardItem(str(p.limits[1]))
+                    item1_5 = QtGui.QStandardItem(p.units)
+                    poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5])
+                    break
+                # Add the polydisp item as a child
                 item1.appendRow([poly_item])
-
+            # Param values
             item2 = QtGui.QStandardItem(str(param.default))
+            # TODO: the error column.
+            # Either add a proxy model or a custom view delegate
+            #item_err = QtGui.QStandardItem()
             item3 = QtGui.QStandardItem(str(param.limits[0]))
             item4 = QtGui.QStandardItem(str(param.limits[1]))
@@ -486,4 +529,5 @@
             model.appendRow([item1, item2, item3, item4, item5])
 
+        # Update the counter used for multishell display
         self._last_model_row = self._model_model.rowCount()
 
@@ -571,10 +615,11 @@
         Create a QStandardModelIndex containing default model data
         """
-        name = self._current_parameter_name
+        name = self.kernel_module.name
         if self.is2D:
             name += "2d"
         name = "M%i [%s]" % (self.tab_id, name)
         new_item = GuiUtils.createModelItemWithPlot(QtCore.QVariant(self.data), name=name)
-        self.signalTheory.emit(new_item)
+        # Notify the GUI manager so it can update the theory model in DataExplorer
+        self.communicate.updateTheoryFromPerspectiveSignal.emit(new_item)
 
     def onFit(self):
@@ -582,6 +627,49 @@
         Perform fitting on the current data
         """
-        # TEST FOR DISPLAY.
-        self.calculate1DForModel()
+        #self.calculate1DForModel()
+        pass
+
+    def onPlot(self):
+        """
+        Plot the current set of data
+        """
+        # TODO: reimplement basepage.py/_update_paramv_on_fit
+        if self.data is None or not self._data.is_data:
+            self.createDefault2dData() if self.is2D else self.createDefault1dData()
+        self.calculate2DForModel() if self.is2D else self.calculate1DForModel()
+
+    def onNpts(self, text):
+        """
+        Callback for number of points line edit update
+        """
+        # assumes type/value correctness achieved with QValidator
+        try:
+            self.npts = int(text)
+        except:
+            pass
+
+    def onMinRange(self, text):
+        """
+        Callback for minimum range of points line edit update
+        """
+        # assumes type/value correctness achieved with QValidator
+        try:
+            self.q_range_min = float(text)
+            # set Q range labels on the main tab
+            self.lblMinRangeDef.setText(str(self.q_range_min))
+        except:
+            pass
+
+    def onMaxRange(self, text):
+        """
+        Callback for maximum range of points line edit update
+        """
+        # assumes type/value correctness achieved with QValidator
+        try:
+            self.q_range_max = float(text)
+            # set Q range labels on the main tab
+            self.lblMaxRangeDef.setText(str(self.q_range_max))
+        except:
+            pass
 
     def calculate1DForModel(self):
@@ -589,48 +677,142 @@
         Prepare the fitting data object, based on current ModelModel
         """
-        data = self.data
-        model = self.kernel_module
-        page_id = 0
-        qmin = self.q_range_min
-        qmax = self.q_range_max
-        smearer = None
-        state = None
-        weight = None
-        fid = None
-        toggle_mode_on = False
-        update_chisqr = False
-        source = None
-
-        self.calc_1D = Calc1D(data=data,
-                              model=model,
-                              page_id=page_id,
-                              qmin=qmin,
-                              qmax=qmax,
-                              smearer=smearer,
-                              state=state,
-                              weight=weight,
-                              fid=fid,
-                              toggle_mode_on=toggle_mode_on,
+        self.calc_1D = Calc1D(data=self.data,
+                              model=self.kernel_module,
+                              page_id=0,
+                              qmin=self.q_range_min,
+                              qmax=self.q_range_max,
+                              smearer=None,
+                              state=None,
+                              weight=None,
+                              fid=None,
+                              toggle_mode_on=False,
                               completefn=self.complete1D,
-                              update_chisqr=update_chisqr,
+                              update_chisqr=True,
                               exception_handler=self.calcException,
-                              source=source)
-        self.calc_1D.queue()
-
-    def complete1D(self, x, y, page_id, elapsed, index, model,
-                   weight=None, fid=None,
-                   toggle_mode_on=False, state=None,
-                   data=None, update_chisqr=True,
-                   source='model', plot_result=True):
+                              source=None)
+        # Instead of starting the thread with
+        #   self.calc_1D.queue()
+        # let's try running the async request
+        calc_thread = threads.deferToThread(self.calc_1D.compute)
+        calc_thread.addCallback(self.complete1D)
+
+    def complete1D(self, return_data):
         """
         Plot the current data
-        Should be a rewrite of fitting.py/_complete1D
-        """
-        print "THREAD FINISHED"
+        """
+        # Unpack return data from Calc1D
+        x, y, page_id, state, weight,\
+        fid, toggle_mode_on, \
+        elapsed, index, model,\
+        data, update_chisqr, source = return_data
+
+        # Create the new plot
+        new_plot = Data1D(x=x, y=y)
+        new_plot.is_data = False
+        new_plot.dy = numpy.zeros(len(y))
+        _yaxis, _yunit = data.get_yaxis()
+        _xaxis, _xunit = data.get_xaxis()
+        new_plot.title = data.name
+
+        new_plot.group_id = data.group_id
+        if new_plot.group_id == None:
+            new_plot.group_id = data.group_id
+        new_plot.id = str(self.tab_id) + " " + data.name
+        new_plot.name = model.name + " [" + data.name + "]"
+        new_plot.xaxis(_xaxis, _xunit)
+        new_plot.yaxis(_yaxis, _yunit)
+
+        # Assign the new Data1D object-wide
+        self._data = new_plot
+        self.createTheoryIndex()
+
+        #output=self._cal_chisqr(data=data,
+        #                        fid=fid,
+        #                        weight=weight,
+        #                        page_id=page_id,
+        #                        index=index)
+
+    def calculate2DForModel(self):
+        """
+        Prepare the fitting data object, based on current ModelModel
+        """
+        self.calc_2D = Calc2D(data=self.data,
+                              model=self.kernel_module,
+                              page_id=0,
+                              qmin=self.q_range_min,
+                              qmax=self.q_range_max,
+                              smearer=None,
+                              state=None,
+                              weight=None,
+                              fid=None,
+                              toggle_mode_on=False,
+                              completefn=self.complete2D,
+                              update_chisqr=True,
+                              exception_handler=self.calcException,
+                              source=None)
+
+        # Instead of starting the thread with
+        #    self.calc_2D.queue()
+        # let's try running the async request
+        calc_thread = threads.deferToThread(self.calc_2D.compute)
+        calc_thread.addCallback(self.complete2D)
+
+    def complete2D(self, return_data):
+        """
+        Plot the current data
+        Should be a rewrite of fitting.py/_complete2D
+        """
+        image, data, page_id, model, state, toggle_mode_on,\
+        elapsed, index, fid, qmin, qmax, weight, \
+        update_chisqr, source = return_data
+
+        numpy.nan_to_num(image)
+        new_plot = Data2D(image=image, err_image=data.err_data)
+        new_plot.name = model.name + '2d'
+        new_plot.title = "Analytical model 2D "
+        new_plot.id = str(page_id) + " " + data.name
+        new_plot.group_id = str(page_id) + " Model2D"
+        new_plot.detector = data.detector
+        new_plot.source = data.source
+        new_plot.is_data = False
+        new_plot.qx_data = data.qx_data
+        new_plot.qy_data = data.qy_data
+        new_plot.q_data = data.q_data
+        new_plot.mask = data.mask
+        ## plot boundaries
+        new_plot.ymin = data.ymin
+        new_plot.ymax = data.ymax
+        new_plot.xmin = data.xmin
+        new_plot.xmax = data.xmax
+
+        title = data.title
+
+        new_plot.is_data = False
+        if data.is_data:
+            data_name = str(data.name)
+        else:
+            data_name = str(model.__class__.__name__) + '2d'
+
+        if len(title) > 1:
+            new_plot.title = "Model2D for %s " % model.name + data_name
+        new_plot.name = model.name + " [" + \
+                                    data_name + "]"
+
+        # Assign the new Data2D object-wide
+        self._data = new_plot
+        self.createTheoryIndex()
+
+        #output=self._cal_chisqr(data=data,
+        #                        weight=weight,
+        #                        fid=fid,
+        #                        page_id=page_id,
+        #                        index=index)
+        #    self._plot_residuals(page_id=page_id, data=data, fid=fid,
+        #                            index=index, weight=weight)
 
     def calcException(self, etype, value, tb):
         """
-        """
-        print "THREAD EXCEPTION"
+        Something horrible happened in the deferred. Cry me a river.
+        """
         logging.error("".join(traceback.format_exception(etype, value, tb)))
         msg = traceback.format_exception(etype, value, tb, limit=1)
@@ -640,5 +822,5 @@
         Updates parameter name from <param_name>[n_shell] to <param_name>value
         """
-        assert('[' in param_name)
+        assert '[' in param_name
         return param_name[:param_name.index('[')]+str(value)
 
@@ -646,6 +828,4 @@
         """
         Setting table properties
-        :param table:
-        :return:
         """
         # Table properties
@@ -679,9 +859,6 @@
 
             # Potential multishell params
-            #length_control = param.length_control
-            #if length_control in param.name:
-
             checked_list = ["Distribution of "+param.name, str(param.default),
-                            str(param.limits[0]),str(param.limits[1]),
+                            str(param.limits[0]), str(param.limits[1]),
                             "35", "3", ""]
             self.addCheckedListToModel(self._poly_model, checked_list)
@@ -689,7 +866,7 @@
             #TODO: Need to find cleaner way to input functions
             func = QtGui.QComboBox()
-            func.addItems(['rectangle','array','lognormal','gaussian','schulz',])
-            func_index = self.lstPoly.model().index(row,6)
-            self.lstPoly.setIndexWidget(func_index,func)
+            func.addItems(['rectangle', 'array', 'lognormal', 'gaussian', 'schulz',])
+            func_index = self.lstPoly.model().index(row, 6)
+            self.lstPoly.setIndexWidget(func_index, func)
 
         self.addPolyHeadersToModel(self._poly_model)
@@ -767,11 +944,12 @@
                     # Find param in volume_params
                     for p in self.model_parameters.form_volume_parameters:
-                        if p.name == par.name:
-                            item1_2 = QtGui.QStandardItem(str(p.default))
-                            item1_3 = QtGui.QStandardItem(str(p.limits[0]))
-                            item1_4 = QtGui.QStandardItem(str(p.limits[1]))
-                            item1_5 = QtGui.QStandardItem(p.units)
-                            poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5])
-                            break
+                        if p.name != par.name:
+                            continue
+                        item1_2 = QtGui.QStandardItem(str(p.default))
+                        item1_3 = QtGui.QStandardItem(str(p.limits[0]))
+                        item1_4 = QtGui.QStandardItem(str(p.limits[1]))
+                        item1_5 = QtGui.QStandardItem(p.units)
+                        poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5])
+                        break
                     item1.appendRow([poly_item])
 
