Index: DataLoader/extensions/smearer.cpp
===================================================================
--- DataLoader/extensions/smearer.cpp	(revision 58598621b309b5bbe6274791cf8c235063c194ce)
+++ DataLoader/extensions/smearer.cpp	(revision 65883cfae638998c33f8e6c79bb60efbd277e67d)
@@ -230,5 +230,5 @@
  *
  */
-void BaseSmearer :: get_bin_range(int i, double* q, double* q_min, double* q_max) {
+int BaseSmearer :: get_bin_range(int i, double* q, double* q_min, double* q_max) {
 	if (even_binning) {
 		double step = (qmax-qmin)/((double)nbins-1.0);
@@ -236,5 +236,6 @@
 		*q_min = *q - 0.5*step;
 		*q_max = *q + 0.5*step;
-	} else {
+		return 1;
+	} else if (i>=0 && i<nbins) {
 		*q = q_values[i];
 		if (i==0) {
@@ -250,5 +251,7 @@
 			*q_max = *q + (q_values[i+1]-q_values[i])/2.0;
 		}
-	}
+		return 1;
+	}
+	return -1;
 }
 
Index: DataLoader/extensions/smearer.hh
===================================================================
--- DataLoader/extensions/smearer.hh	(revision 58598621b309b5bbe6274791cf8c235063c194ce)
+++ DataLoader/extensions/smearer.hh	(revision 65883cfae638998c33f8e6c79bb60efbd277e67d)
@@ -50,5 +50,5 @@
 	int get_nbins() { return nbins; }
 	// Get the q range of a particular bin
-	virtual void get_bin_range(int, double*, double*, double*);
+	virtual int get_bin_range(int, double*, double*, double*);
 };
 
Index: DataLoader/extensions/smearer_module.cpp
===================================================================
--- DataLoader/extensions/smearer_module.cpp	(revision 58598621b309b5bbe6274791cf8c235063c194ce)
+++ DataLoader/extensions/smearer_module.cpp	(revision 65883cfae638998c33f8e6c79bb60efbd277e67d)
@@ -161,7 +161,12 @@
 	BaseSmearer* s = static_cast<BaseSmearer *>(temp);
 
+	if(s->get_nbins()<=0 || s->get_nbins()<=bin) {
+		return NULL;
+	}
+
 	double q, q_min, q_max;
-	s->get_bin_range(bin, &q, &q_min, &q_max);
-
+	if (s->get_bin_range(bin, &q, &q_min, &q_max)<0) {
+		return NULL;
+	}
 	return Py_BuildValue("d", q);
 }
Index: DataLoader/qsmearing.py
===================================================================
--- DataLoader/qsmearing.py	(revision 58598621b309b5bbe6274791cf8c235063c194ce)
+++ DataLoader/qsmearing.py	(revision 65883cfae638998c33f8e6c79bb60efbd277e67d)
@@ -106,4 +106,9 @@
             @param q_max: maximum q-value to smear 
         """
+        # If this is the first time we call for smearing,
+        # initialize the C++ smearer object first
+        if not self._init_complete:
+            self._initialize_smearer()
+            
         if q_min == None:
             q_min = self.min
@@ -118,12 +123,15 @@
 
         step = (self.max-self.min)/(self.nbins-1.0)
-        for i in range(self.nbins):
-            q_i = smearer.get_q(self._smearer, i)
-            if (q_i >= _qmin_unsmeared) and (q_i <= _qmax_unsmeared):
-                # Identify first and last bin
-                if _first_bin is None:
-                    _first_bin = i
-                else:
-                    _last_bin  = i
+        try:
+            for i in range(self.nbins):
+                q_i = smearer.get_q(self._smearer, i)
+                if (q_i >= _qmin_unsmeared) and (q_i <= _qmax_unsmeared):
+                    # Identify first and last bin
+                    if _first_bin is None:
+                        _first_bin = i
+                    else:
+                        _last_bin  = i
+        except:
+            raise RuntimeError, "_BaseSmearer.get_bin_range: error getting range\n  %s" % sys.exc_value
                
         return _first_bin, _last_bin
@@ -151,5 +159,7 @@
         # Storage for smeared I(q)   
         iq_out = numpy.zeros(self.nbins)
-        smearer.smear(self._smearer, iq_in, iq_out, first_bin, last_bin)
+        smear_output = smearer.smear(self._smearer, iq_in, iq_out, first_bin, last_bin)
+        if smear_output < 0:
+            raise RuntimeError, "_BaseSmearer: could not smear, code = %g" % smear_output
         return iq_out
     
@@ -184,4 +194,5 @@
         ## Smearing matrix
         self._weights = None
+        self.qvalues  = None
         
     def _initialize_smearer(self):
@@ -275,4 +286,5 @@
         ## Smearing matrix
         self._weights = None
+        self.qvalues  = None
         
     def _initialize_smearer(self):
