Index: src/sas/dataloader/readers/cansas_reader.py
===================================================================
--- src/sas/dataloader/readers/cansas_reader.py	(revision 682c432d9d62b6579bcdee8cedf8793d5d84f77b)
+++ src/sas/dataloader/readers/cansas_reader.py	(revision 5ce7f17e66dc0bd0cabff37dedf011bc6ec0a929)
@@ -322,5 +322,4 @@
                 value_unit = local_unit
             except:
-                print sys.exc_info()
                 err_msg = "CanSAS reader: unknown error converting "
                 err_msg += "\"{0}\" unit [{1}]"
@@ -990,5 +989,5 @@
                 self.append(node, entry_node)
 
-    def _check_origin(self, entry_node, doc):
+    def _check_origin(self, entry_node, doc, frm):
         """
         Return the document, and the SASentry node associated with
@@ -1000,5 +999,6 @@
         :param doc: entire xml tree
         """
-        frm = inspect.stack()[1]
+        if not frm:
+            frm = inspect.stack()[1]
         mod_name = frm[1].replace("\\", "/").replace(".pyc", "")
         mod_name = mod_name.replace(".py", "")
@@ -1011,5 +1011,5 @@
             node_list = doc.getElementsByTagName(node_name)
             entry_node = node_list.item(0)
-        return entry_node
+        return doc, entry_node
 
     def _to_xml_doc(self, datainfo):
@@ -1061,5 +1061,6 @@
         # If the calling function was not the cansas reader, return a minidom
         #      object rather than an lxml object.
-        entry_node = self._check_origin(entry_node, doc)
+        frm = inspect.stack()[1]
+        doc, entry_node = self._check_origin(entry_node, doc, frm)
         return doc, entry_node
 
Index: src/sas/dataloader/readers/xml_reader.py
===================================================================
--- src/sas/dataloader/readers/xml_reader.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/dataloader/readers/xml_reader.py	(revision 5ce7f17e66dc0bd0cabff37dedf011bc6ec0a929)
@@ -1,5 +1,5 @@
 """
     Generic XML read and write utility
-    
+
     Usage: Either extend xml_reader or add as a class variable.
 """
@@ -7,9 +7,9 @@
 #This software was developed by the University of Tennessee as part of the
 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
-#project funded by the US National Science Foundation. 
-#If you use DANSE applications to do scientific research that leads to 
-#publication, we ask that you acknowledge the use of the software with the 
+#project funded by the US National Science Foundation.
+#If you use DANSE applications to do scientific research that leads to
+#publication, we ask that you acknowledge the use of the software with the
 #following sentence:
-#This work benefited from DANSE software developed under NSF award DMR-0520547. 
+#This work benefited from DANSE software developed under NSF award DMR-0520547.
 #copyright 2008,2009 University of Tennessee
 #############################################################################
@@ -25,9 +25,9 @@
     Generic XML read and write class. Mostly helper functions.
     Makes reading/writing XML a bit easier than calling lxml libraries directly.
-    
+
     :Dependencies:
         This class requires lxml 2.3 or higher.
     """
-    
+
     xml = None
     xmldoc = None
@@ -37,6 +37,6 @@
     encoding = None
     processing_instructions = None
-    
-    def __init__(self, xml = None, schema = None):
+
+    def __init__(self, xml=None, schema=None):
         self.xml = xml
         self.schema = schema
@@ -51,5 +51,5 @@
         else:
             self.schemadoc = None
-    
+
     def reader(self):
         """
@@ -57,9 +57,9 @@
         """
         if self.validate_xml():
-            self.xmldoc = etree.parse(self.xml, parser = PARSER)
+            self.xmldoc = etree.parse(self.xml, parser=PARSER)
         else:
             raise etree.XMLSchemaValidateError(self, self.find_invalid_xml())
         return self.xmldoc
-    
+
     def set_xml_file(self, xml):
         """
@@ -68,5 +68,5 @@
         try:
             self.xml = xml
-            self.xmldoc = etree.parse(self.xml, parser = PARSER)
+            self.xmldoc = etree.parse(self.xml, parser=PARSER)
             self.xmlroot = self.xmldoc.getroot()
         except etree.XMLSyntaxError as xml_error:
@@ -76,5 +76,5 @@
             self.xmldoc = None
             self.xmlroot = None
-    
+
     def set_schema(self, schema):
         """
@@ -83,5 +83,5 @@
         try:
             self.schema = schema
-            self.schemadoc = etree.parse(self.schema, parser = PARSER)
+            self.schemadoc = etree.parse(self.schema, parser=PARSER)
         except etree.XMLSyntaxError as xml_error:
             logging.info(xml_error)
@@ -89,5 +89,5 @@
             self.schema = None
             self.schemadoc = None
-    
+
     def validate_xml(self):
         """
@@ -100,5 +100,5 @@
             valid = schema_check.validate(self.xmldoc)
         return valid
-    
+
     def find_invalid_xml(self):
         """
@@ -113,5 +113,5 @@
             first_error = str(err)
         return first_error
-    
+
     def parse_schema_and_doc(self):
         """
@@ -120,16 +120,16 @@
         self.set_xml_file(self.xml)
         self.set_schema(self.schema)
-        
+
     def to_string(self, elem, pretty_print=False, encoding=None):
         """
         Converts an etree element into a string
         """
-        return etree.tostring(elem, pretty_print = pretty_print, \
-                              encoding = encoding)
-    
+        return etree.tostring(elem, pretty_print=pretty_print, \
+                              encoding=encoding)
+
     def break_processing_instructions(self, string, dic):
         """
         Method to break a processing instruction string apart and add to a dict
-        
+
         :param string: A processing instruction as a string
         :param dic: The dictionary to save the PIs to
@@ -142,5 +142,5 @@
         dic[new_pi_name] = attr
         return dic
-    
+
     def set_processing_instructions(self):
         """
@@ -164,14 +164,14 @@
             del dic['xml']
         self.processing_instructions = dic
-        
+
     def set_encoding(self, attr_str):
         """
         Find the encoding in the xml declaration and save it as a string
-        
+
         :param attr_str: All attributes as a string
             e.g. "foo1="bar1" foo2="bar2" foo3="bar3" ... foo_n="bar_n""
         """
         attr_str = attr_str.replace(" = ", "=")
-        attr_list = attr_str.split( )
+        attr_list = attr_str.split()
         for item in attr_list:
             name_value = item.split("\"=")
@@ -182,6 +182,6 @@
                 return
         self.encoding = None
-        
-    def _create_unique_key(self, dictionary, name, numb = 0):
+
+    def _create_unique_key(self, dictionary, name, numb=0):
         """
         Create a unique key value for any dictionary to prevent overwriting
@@ -198,25 +198,25 @@
             name = self._create_unique_key(dictionary, name, numb)
         return name
-    
+
     def create_tree(self, root):
         """
         Create an element tree for processing from an etree element
-        
+
         :param root: etree Element(s) 
         """
         return etree.ElementTree(root)
-    
+
     def create_element_from_string(self, xml_string):
         """
         Create an element from an XML string
-        
+
         :param xml_string: A string of xml
         """
         return etree.fromstring(xml_string)
-    
+
     def create_element(self, name, attrib=None, nsmap=None):
         """
         Create an XML element for writing to file
-        
+
         :param name: The name of the element to be created
         """
@@ -224,9 +224,9 @@
             attrib = {}
         return etree.Element(name, attrib, nsmap)
-    
+
     def write_text(self, elem, text):
         """
         Write text to an etree Element
-        
+
         :param elem: etree.Element object
         :param text: text to write to the element
@@ -234,9 +234,9 @@
         elem.text = text
         return elem
-    
+
     def write_attribute(self, elem, attr_name, attr_value):
         """
         Write attributes to an Element
-        
+
         :param elem: etree.Element object
         :param attr_name: attribute name to write
@@ -245,9 +245,9 @@
         attr = elem.attrib
         attr[attr_name] = attr_value
-        
+
     def return_processing_instructions(self):
         """
         Get all processing instructions saved when loading the document
-        
+
         :param tree: etree.ElementTree object to write PIs to
         """
@@ -259,9 +259,9 @@
                 pi_list.append(pi_item)
         return pi_list
-    
+
     def append(self, element, tree):
         """
         Append an etree Element to an ElementTree.
-        
+
         :param element: etree Element to append
         :param tree: ElementTree object to append to
@@ -269,9 +269,9 @@
         tree = tree.append(element)
         return tree
-    
+
     def ebuilder(self, parent, elementname, text=None, attrib=None):
         """
         Use lxml E builder class with arbitrary inputs.
-        
+
         :param parnet: The parent element to append a child to
         :param elementname: The name of the child in string form
@@ -285,3 +285,2 @@
         parent = parent.append(elem)
         return parent
-        
