diff --git a/theme.inc b/theme.inc
index 9e833ec..03da285 100644
--- a/theme.inc
+++ b/theme.inc
@@ -90,6 +90,7 @@ function template_preprocess_views_calc_table(&$vars) {
   if (!isset($vars['view']->row_index)) $vars['view']->row_index = '';
 
   $view = $vars['view'];
+  $view->row_index = "";
   if (!empty($view->views_calc_calculation)) {
     $vars['rows'] = array();
     return;
@@ -221,10 +222,10 @@ function template_preprocess_views_calc_table(&$vars) {
   $vars['totals'] = array();
   $vars['sub_totals'] = array();
   if ($view->query->pager->get_total_items() > $view->get_items_per_page()
-      && $view->sub_totals) {
+      && isset($view->sub_totals)) {
     views_calc_table_total($vars, 'sub_totals', $view->sub_totals);
   }
-  if ($view->totals) {
+  if (isste($view->totals)) {
     views_calc_table_total($vars, 'totals', $view->totals);
   }
 
@@ -259,7 +260,8 @@ function views_calc_table_total(&$vars, $key, $totals) {
     else {
       $query_alias = $field->field_alias;
     }
-    $baserow->{$query_alias} = $totals->{$query_alias};
+    //$baserow->{$query_alias} = $totals->{$query_alias};
+    $baserow->{$query_alias} = isset($totals->{$query_alias}) ? $totals->{$query_alias} : '';
   }
   // Build aggregation rows, one per function.
   foreach ($view->views_calc_fields as $calc => $calc_fields) {
diff --git a/views_calc_handler_sort.inc b/views_calc_handler_sort.inc
index 6ce1b58..47c813e 100644
--- a/views_calc_handler_sort.inc
+++ b/views_calc_handler_sort.inc
@@ -6,7 +6,8 @@
 class views_calc_handler_sort extends views_handler_sort {
   function query() {
     $result = _views_calc_fields();
-    while ($result as $calc_field) {
+    //while ($result as $calc_field) {
+    foreach ($result as $calc_field){
       if ($this->field == "cid" . $calc_field->cid) {
         foreach (explode(',', $calc_field->tablelist) as $table) {
           $this->view->query->add_table($table);
