diff --git a/html/include/tsorter.js b/html/include/tsorter.js
index 76e4570d857be847772b1022ce95f791328a7435..dbac680353119f5d0a7835f20b2864ef6c095907 100644
--- a/html/include/tsorter.js
+++ b/html/include/tsorter.js
@@ -79,7 +79,7 @@ var tsorter = (function()
                 if( that.prevCol !== -1 && that.ths[that.prevCol].className !== 'exc_cell'){
                     that.ths[that.prevCol].className = '';
                 }
-                that.quicksort(0, that.trs.length);
+                that.quicksort(0, that.trs.length - 1);
             }
             that.prevCol = that.column;
         },
@@ -152,7 +152,7 @@ var tsorter = (function()
             var that = this,
                 i;
 
-            for( i = 1; i < that.trs.length; i++ ) {
+            for( i = 1; i < (that.trs.length - 1); i++ ) {
                 that.tbody.insertBefore( that.trs[i], that.trs[0] );
             }
         },
diff --git a/include/class_divSelectBox.inc b/include/class_divSelectBox.inc
index b360b4b2dc4795c6159273d1bc71e416f9f240ee..722a8daaf62168930796f83f831ef2ae77121f9a 100644
--- a/include/class_divSelectBox.inc
+++ b/include/class_divSelectBox.inc
@@ -105,10 +105,12 @@ class divSelectBox
                   ">\n";
     $s_return .= $this->_generatePage();
     $s_return .= '</table></div></div>';
-    $s_return .=
+    if ($this->headers !== FALSE) {
+      $s_return .=
         '<script type="text/javascript">
           var sorter'.$this->id.' = tsorter.create(\''.$this->id.'\');
         </script>';
+    }
     return $s_return;
   }