diff --git a/taxonomy_subterms.info b/taxonomy_subterms.info
index 7fb9c5d..2cbdbe1 100644
--- a/taxonomy_subterms.info
+++ b/taxonomy_subterms.info
@@ -1,5 +1,13 @@
 name = Taxonomy subterms
 description = "Display subterms in terms page."
 dependencies[] = taxonomy
-core = 6.x
-package = Taxonomy
\ No newline at end of file
+core = 7.x
+package = Taxonomy
+configure = admin/config/taxonomy_subterms
+
+; Information added by drupal.org packaging script on 2011-02-25
+version = "7.x-1.x-dev"
+core = "7.x"
+project = "taxonomy_subterms"
+datestamp = "1298620361"
+
diff --git a/taxonomy_subterms.install b/taxonomy_subterms.install
index 7eef504..8d5cedc 100644
--- a/taxonomy_subterms.install
+++ b/taxonomy_subterms.install
@@ -14,7 +14,7 @@ function taxonomy_subterms_install() {
   taxonomy_subterms_schema_alter($new_schema);
   foreach ($new_schema as $table => &$info) {
     foreach ($info['fields'] as $field => &$spec) {
-      db_add_field($ret, $table, $field, $spec);
+      db_add_field($table, $field, $spec);
     }
   }
 }
@@ -29,7 +29,7 @@ function taxonomy_subterms_uninstall() {
   taxonomy_subterms_schema_alter($new_schema);
   foreach ($new_schema as $table => &$info) {
     foreach ($info['fields'] as $field => &$spec) {
-      db_drop_field($ret, $table, $field);
+      db_drop_field($table, $field);
     }
   }
 }
@@ -38,29 +38,29 @@ function taxonomy_subterms_uninstall() {
  * Implementation of hook_menu_alter().
  */
 function taxonomy_subterms_schema_alter(&$schema) {
-  $schema['term_data']['fields']['taxonomy_subterms'] = array(
+  $schema['taxonomy_term_data']['fields']['taxonomy_subterms'] = array(
     'type' => 'int',
     'size' => 'tiny',
     'default' => TAXONOMY_SUBTERMS_INHERIT,
-    'description' => 'Taxonomy suterms depth.',
+    'description' => 'Taxonomy subterms depth.',
   );
-  $schema['vocabulary']['fields']['taxonomy_subterms'] = array(
+  $schema['taxonomy_vocabulary']['fields']['taxonomy_subterms'] = array(
     'type' => 'int', 
     'size' => 'tiny',
     'default' => TAXONOMY_SUBTERMS_DISABLE,
-    'description' => 'Taxonomy suterms depth.',
+    'description' => 'Taxonomy subterms depth.',
   );
-  $schema['term_data']['fields']['taxonomy_subterms_map'] = array(
+  $schema['taxonomy_term_data']['fields']['taxonomy_subterms_map'] = array(
     'type' => 'int',
     'size' => 'tiny',
     'default' => TAXONOMY_SUBTERMS_INHERIT,
-    'description' => 'Taxonomy suterms subterms map.',
+    'description' => 'Taxonomy subterms map.',
   );
-  $schema['vocabulary']['fields']['taxonomy_subterms_map'] = array(
+  $schema['taxonomy_vocabulary']['fields']['taxonomy_subterms_map'] = array(
     'type' => 'int', 
     'size' => 'tiny',
     'default' => TAXONOMY_SUBTERMS_DISABLE,
-    'description' => 'Taxonomy suterms subterms map.',
+    'description' => 'Taxonomy subterms map.',
   );
 }
 
diff --git a/taxonomy_subterms.module b/taxonomy_subterms.module
index fbca1d2..27826c5 100644
--- a/taxonomy_subterms.module
+++ b/taxonomy_subterms.module
@@ -28,19 +28,27 @@ define('TAXONOMY_SUBTERMS_INHERIT', -2);
  * Implementation of hook_menu_alter().
  */
 function taxonomy_subterms_menu_alter(&$items) {
-  if (isset($items['taxonomy/term/%']['page callback'])) {
-    $item = &$items['taxonomy/term/%'];
+  
+  if (!empty($items['taxonomy/term/%taxonomy_term'])) {
+    $item = $items['taxonomy/term/%taxonomy_term'];
     // Store the original configuration, so we can pass it on to our own callback.
     $callback = $item['page callback'];
     $arguments = $item['page arguments'];
     $file = $item['file'];
     $filepath = isset($item['file path']) ? $item['file path'] : drupal_get_path('module', $item['module']);
 
+
     // Alter the original callback.
     $item['page callback'] = 'taxonomy_subterms_term_page';
     $item['page arguments'] = array_merge(array(2, $callback, $file, $filepath), $arguments);
     $item['file'] = 'taxonomy_subterms.pages.inc';
     $item['file path'] = drupal_get_path('module', 'taxonomy_subterms');
+
+    //save this back 
+    $items['taxonomy/term/%taxonomy_term'] = $item;
+  
+  } else {
+//    watchdog('GDB', 'taxonomy/term/%taxonomy_term not defined');
   }
 }
 
@@ -56,7 +64,7 @@ function taxonomy_subterms_vocab_submit($form, &$form_state) {
     'taxonomy_subterms' => $form_state['values']['taxonomy_subterms']['depth'],
     'taxonomy_subterms_map' => $form_state['values']['taxonomy_subterms']['map'],
   );
-  drupal_write_record('vocabulary', $record, 'vid');
+  drupal_write_record('taxonomy_vocabulary', $record, 'vid');
 }
 
 /**
@@ -64,7 +72,7 @@ function taxonomy_subterms_vocab_submit($form, &$form_state) {
  */
 function taxonomy_subterms_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'taxonomy_form_vocabulary') {
-    $vocab=$form['#parameters'][2];
+    $vocab=$form['#vocabulary'];
 
     $form['taxonomy_subterms'] = array(
       '#type' => 'fieldset',
@@ -82,7 +90,7 @@ function taxonomy_subterms_form_alter(&$form, $form_state, $form_id) {
           TAXONOMY_SUBTERMS_INFINITY => t('Infinity'),
           TAXONOMY_SUBTERMS_DISABLE => t('Disabled')
         )+array_combine(range(1, 10), range(1, 10)),
-      '#default_value' => $vocab['taxonomy_subterms'],
+      '#default_value' => $vocab->taxonomy_subterms,
       '#description' => t('Recursion depth for subterms.'),
     );
     
@@ -93,7 +101,7 @@ function taxonomy_subterms_form_alter(&$form, $form_state, $form_id) {
           TAXONOMY_SUBTERMS_DISABLE => t('Disabled'),
           1 => t('Enabled'),
         ),
-      '#default_value' => $vocab['taxonomy_subterms_map'],
+      '#default_value' => $vocab->taxonomy_subterms_map,
       '#description' => t('Subterms map.'),
     );
     
@@ -105,8 +113,12 @@ function taxonomy_subterms_form_alter(&$form, $form_state, $form_id) {
     $form['#submit'][] = 'taxonomy_subterms_vocab_submit';
   }
   elseif ($form_id == 'taxonomy_form_term') {
-    $term=(array)$form['#parameters'][3];
-    
+    $term=$form['#term'];
+
+    //safe-guard creating new - setting default values  
+    if (empty($term['taxonomy_subterms']))          $term['taxonomy_subterms'] = TAXONOMY_SUBTERMS_INHERIT;
+    if (empty($term['taxonomy_subterms_map']))   $term['taxonomy_subterms_map'] = TAXONOMY_SUBTERMS_INHERIT;
+
     $form['taxonomy_subterms'] = array(
       '#type' => 'fieldset',
       '#collapsible' => TRUE,
@@ -130,13 +142,13 @@ function taxonomy_subterms_form_alter(&$form, $form_state, $form_id) {
 
     $form['taxonomy_subterms']['map'] = array(
       '#type' => 'select',
-      '#title' => t('Taxonomy subterms'),
+      '#title' => t('Taxonomy subterms map'),
       '#options' => array(
           TAXONOMY_SUBTERMS_INHERIT => t('Inherit from vocabulary'),
           TAXONOMY_SUBTERMS_DISABLE => t('Disabled'),
           1 => t('Enabled'),
           ),
-      '#default_value' => $term['taxonomy_subterms'],
+      '#default_value' => $term['taxonomy_subterms_map'],
       '#description' => t('Recursion depth for subterms.'),
     );
     
@@ -161,7 +173,7 @@ function taxonomy_subterms_term_submit($form, &$form_state) {
     'taxonomy_subterms' => $form_state['values']['taxonomy_subterms']['depth'],
     'taxonomy_subterms_map' => $form_state['values']['taxonomy_subterms']['map'],
   );
-  drupal_write_record('term_data', $record, 'tid');
+  drupal_write_record('taxonomy_term_data', $record, 'tid');
 }
 
 
@@ -169,7 +181,7 @@ function taxonomy_subterms_term_submit($form, &$form_state) {
  * Implementation of hook_menu().
  */
 function taxonomy_subterms_menu() {
-  $items['admin/settings/taxonomy_subterms'] = array(
+  $items['admin/config/taxonomy_subterms'] = array(
     'title' => 'Taxonomy Subterms',
     'description' => 'Customize how Taxonomy subterms displays terms.',
     'page callback' => 'drupal_get_form',
@@ -184,10 +196,15 @@ function taxonomy_subterms_menu() {
 
 
 /**
- * Implementation of hook_perm().
+ * Implementation of hook_permission().
  */
-function taxonomy_subterms_perm() {
-  return array('administer taxonomy_subterms');
+function taxonomy_subterms_permission() {
+  return array(
+    'administer taxonomy_subterms' => array(
+      'title' => t('Administer Taxonomy Sub Terms'), 
+      'description' => t('Perform administration tasks for my module.')
+    ),
+  );
 }
 
 
@@ -208,7 +225,9 @@ function taxonomy_subterms_theme() {
  */
 function taxonomy_subterms_enable() {
   // we need to come after taxonomy modules...
-  $weight = intval((db_result(db_query("SELECT MAX(weight) FROM {system} WHERE type='%s' AND name IN ('%s', '%s')", 'module', 'taxonomy', 'i18ntaxonomy'))) + 1);
-  db_query("UPDATE {system} SET weight=%d WHERE type='%s' AND name = '%s'", $weight, 'module', 'taxonomy_subterms');
-  db_query("UPDATE {system} SET weight=%d WHERE type='%s' AND name = '%s'", $weight+1, 'module', 'taxonomy_breadcrumb');
+  $weight = intval((db_query("SELECT MAX(weight) FROM {system} WHERE type='module' AND name IN ('taxonomy', 'i18ntaxonomy')")->fetchField()) + 1);
+  db_query("UPDATE {system} SET weight=".($weight+0)." WHERE type='module' AND name = 'taxonomy_subterms'");
+  
+  // not required in Drupal-7;  build-in
+  // db_query("UPDATE {system} SET weight=".($weight+1)." WHERE type='module' AND name = 'taxonomy_breadcrumb'");
 }
\ No newline at end of file
diff --git a/taxonomy_subterms.pages.inc b/taxonomy_subterms.pages.inc
index 2f246f8..dc21973 100644
--- a/taxonomy_subterms.pages.inc
+++ b/taxonomy_subterms.pages.inc
@@ -22,79 +22,94 @@
  * @ return
  *   The return value of the original callback function.
  */
-function taxonomy_subterms_term_page($tid, $callback, $file, $filepath) {
-  if (is_file($filepath .'/'. $file)) {
-    require_once($filepath .'/'. $file);
-  }
-  $arguments = array_slice(func_get_args(), 4);
-  $map=FALSE;
-  $terms = taxonomy_terms_parse_string($tid);
-  if (count($terms['tids'])==1) {
-    //only for single term page
-    $i=array_search($tid, $arguments);
-    $i++;
-    if (!isset($arguments[$i])) {
-      //only if no depth in URL (and op = page)
-      $term=taxonomy_get_term($terms['tids'][0]);
-      $vocab=taxonomy_vocabulary_load($term->vid);
-      
-      $depth=$term->taxonomy_subterms;
-      if ($depth==TAXONOMY_SUBTERMS_INHERIT) {
+ 
+ 
+ 
+function taxonomy_subterms_term_page($term, $callback, $file, $filepath) {
+
+    if (is_file($filepath .'/'. $file)) {
+        require_once($filepath .'/'. $file);
+    }
+    $arguments = array_slice(func_get_args(), 4);
+    $map=FALSE;
+
+    //$term is the taxonomy term object already.... 
+
+    $vocab=taxonomy_vocabulary_load($term->vid);
+
+    $depth=$term->taxonomy_subterms;
+    if ($depth==TAXONOMY_SUBTERMS_INHERIT) {
         $depth=$vocab->taxonomy_subterms;
-      }
-      if ($depth==TAXONOMY_SUBTERMS_INFINITY) {
-        $depth='all';
-      }
-      if ($depth!=TAXONOMY_SUBTERMS_DISABLE) {
-        $arguments[$i]=$depth;
-      }
-      
-      $map=$term->taxonomy_subterms_map;
-      if ($depth==TAXONOMY_SUBTERMS_INHERIT) {
-        $map=$vocab->taxonomy_subterms_map;
-      }
-      if ($map) {
-        $map = taxonomy_get_tree($term->vid, $tid, -1, 1);
-      }
     }
-  }
-  
-  // call "normal" callback
-  $normal_output = call_user_func_array($callback, $arguments);
+    if ($depth==TAXONOMY_SUBTERMS_INFINITY) {
+        $depth=NULL;
+    }
+    if ($depth==TAXONOMY_SUBTERMS_DISABLE) {
+        $depth=0;
+    }
+    
+    $map=$term->taxonomy_subterms_map;
+    if ($map==TAXONOMY_SUBTERMS_INHERIT) {
+       $map=$vocab->taxonomy_subterms_map;
+    }
+    
+     // call "normal" callback
+    $output = call_user_func_array($callback, $arguments);
 
-  if ($map) {
-    $termsmap_output=theme('taxonomy_subterms_termsmap', $map);
-    if (variable_get('taxonomy_subterms_subterms_map_position', 'before') == 'before') {
-      $output = $termsmap_output . $normal_output;
+    //assign a weight....  by default = nothing
+    if (!empty($output["no_content"])) {
+        $output["no_content"]["#weight"] = 3;    // no default weight in taxonomy module....
     }
-    else {
-      $output = $normal_output . $termsmap_output;
+    if (!empty($output["nodes"])) {
+        $output["nodes"]["#weight"] = 3;    // no default weight in taxonomy module....
     }
-  }
-  else $output = $normal_output;
-  return $output;
+    
+    if ($map) {
+        $map = taxonomy_get_tree($term->vid, $term->tid, $depth);
+
+        $termsmap_output=theme('taxonomy_subterms_termsmap', $map);
+        $output["subterms"] = $termsmap_output;
+        
+        // default weight = 1, i.e before.  If not, move down!
+        if (variable_get('taxonomy_subterms_subterms_map_position', 'before') != 'before') {
+          $output["subterms"]["#weight"] = 4;
+        }
+    }
+    
+    return $output;
 }
 
+        
+        
 function theme_taxonomy_subterms_termsmap($terms)
 {
   drupal_add_css(drupal_get_path('module', 'taxonomy_subterms') . '/taxonomy_subterms.css');
-  $output='';
+  $add_descriptions = variable_get('taxonomy_subterms_subterms_map_description', 'no')=='yes';
+        
+  $output = array();
   foreach ($terms as $term)
   {
-    $output .= '<li class="taxonomy-term">';
-    $output .= l(check_plain($term->name), taxonomy_term_path($term));
-    if ($term->description&&variable_get('taxonomy_subterms_subterms_map_description', 'no')=='yes') {
-      $output .= ' <span class="taxonomy-term-description">';
-      $output .= filter_xss_admin($term->description);
-      $output .= '</span>';
+    if ($term->description && $add_descriptions) {
+      $desc = array("#prefix" => "<span class='taxonomy-term-description'>", 
+                        "#markup" => filter_xss_admin($term->description),
+                        "#suffix" => '</span>');
+    } else { 
+      $desc = NULL;
     }
-    $output .= '</li>';
+   
+    $output[] = array("#prefix" => '<li class="taxonomy-term">',
+                      "#markup" => l($term->name, "taxonomy/term/". ($term->tid) ),
+                      "description" => $desc,
+                      "#suffix" => '</li>');
   }
-  return '<ul id="taxonomy-subterms-map">' . $output . '</ul>';
+  return array("#prefix" => '<ul id="taxonomy-subterms-map">',
+                "map" => $output,
+                "#suffix" => '</ul>',
+                "#weight" => 1);
 }
 
 function taxonomy_subterms_select_nodes($tid, $limit, $order = 'n.sticky DESC, n.created DESC') {
-  $sql = 'SELECT DISTINCT(n.nid) FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid WHERE tn.tid = %d AND n.status = 1 ORDER BY '. $order;
+  $sql = 'SELECT DISTINCT(n.nid) FROM {node} n INNER JOIN {taxonomy_index} tn ON n.vid = tn.vid WHERE tn.tid = %d AND n.status = 1 ORDER BY '. $order;
   $sql = db_rewrite_sql($sql);
   $nid = db_result(db_query_range($sql, array($tid), 0, $limit));
   if ($nid) return node_load($nid);
