diff --git a/.cvsignore b/.cvsignore
deleted file mode 100644
index 3a4edf6..0000000
--- a/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-.project
diff --git a/README.txt b/README.txt
index df0dcdc..c0c00ad 100644
--- a/README.txt
+++ b/README.txt
@@ -37,7 +37,7 @@ that determine the way nodeorder works.
 
 TECHNICAL NOTES:
 
-Upon installation, this module adds a new column (weight_in_tid) to the
+Upon installation, this module adds a new column (weight) to the
 term_node table.  Adding a column to a core table?  Are you crazy?  Yeah,
 I guess so ... but it lets us keep the module's code very small since
 most everything works through taxonomy.  Also it helps to avoid an extra
diff --git a/nodeorder-admin-display-form.tpl.php b/nodeorder-admin-display-form.tpl.php
deleted file mode 100644
index e73ee45..0000000
--- a/nodeorder-admin-display-form.tpl.php
+++ /dev/null
@@ -1,52 +0,0 @@
-﻿<?php
-
-/**
- * @file nodeorder-admin-display-form.tpl.php
- * Default theme implementation to order nodes.
- *
- * Available variables:
- * - $node_listing: An array of nodes.
- * - $form_submit: Form submit button.
- *
- *
- * Each $data in $node_listing[$i] contains:
- * - $data->node_title: Node title.
- * - $data->weight: Drop-down menu for setting weights.
- * - $data->tid
- * - $data->nid
- *
- * @see template_preprocess_nodeorder_admin_display_form()
- * @see theme_nodeorder_admin_display()
- */
-?>
-<?php
-  // Add table javascript.
-  drupal_add_js('misc/tableheader.js');
-  drupal_add_js(drupal_get_path('module', 'nodeorder') .'/nodeorder.js');
-  drupal_add_tabledrag('ordernodes', 'order', 'sibling', 'nodeorder-weight');
-?>
-<table id="ordernodes" class="sticky-enabled">
-  <thead>
-    <tr>
-      <th colspan=2><?php print t('Node title'); ?></th>
-    </tr>
-  </thead>
-  <tbody>
-    <?php $row = 0; ?>
-    <?php if (isset($node_listing) && sizeof($node_listing) > 0): ?> 
-      <?php foreach ($node_listing as $key => $data): ?>
-        <tr class="draggable <?php print $row % 2 == 0 ? 'odd' : 'even'; ?><?php print $data->row_class ? ' '. $data->row_class : ''; ?>">
-          <td class="node"><?php print $data->node_title; ?></td>
-		  <td><?php print $data->weight; ?></td>
-        </tr>
-        <?php $row++; ?>
-      <?php endforeach; ?>
-    <?php else: ?>
-      <tr>
-        <td><em><?php print t('No nodes available.'); ?></em></td>
-      </tr>
-    <?php endif; ?>
-  </tbody>
-</table>
-
-<?php print $form_submit; ?>
\ No newline at end of file
diff --git a/nodeorder.admin.inc b/nodeorder.admin.inc
index 4873bf9..967503a 100644
--- a/nodeorder.admin.inc
+++ b/nodeorder.admin.inc
@@ -4,81 +4,55 @@
  * @file
  * Admin page callbacks for the nodeorder module.
  */
- 
- /**
- * Menu callback for nodeorder/order.
- */
-function nodeorder_admin_display($tid) {
-  return drupal_get_form('nodeorder_admin_display_form', $tid);
-}
 
 /**
  * Generate main blocks administration form.
  */
-function nodeorder_admin_display_form(&$form_state, $tid) {
+function nodeorder_admin_display_form($form, &$form_state, $tid) {
+  global $pager_page_array, $pager_total, $pager_total_items;
+  
+  $page            = isset($_GET['page']) ? $_GET['page'] : 0;
+  $page_increment  = variable_get('taxonomy_terms_per_page_admin', 100);  // Number of terms per page.
+  $page_entries    = 0;   // Elements shown on this page.
+  $before_entries  = 0;   // Elements at the root level before this page.
+  $after_entries   = 0;   // Elements at the root level after this page.
+  $root_entries    = 0;   // Elements at the root level on this page.
+  
+  $term = taxonomy_term_load($tid);
   // Build form tree
   $form = array(
-    '#tree' => TRUE
+    '#tree' => TRUE,
+    '#parent_fields' => FALSE,
+    '#term' => $term,
   );
+  drupal_set_title(t('Order nodes for <em>%term_name</em>', array('%term_name' => $term->name)), PASS_THROUGH);
   
-  $term = taxonomy_get_term($tid);
-  drupal_set_title(t('Order nodes for <em>%term_name</em>', array( '%term_name' => $term->name)));
-  
-  $order = 'n.sticky DESC, tn0.weight_in_tid';
-  $result = nodeorder_select_nodes(array($tid), 'and', 0, FALSE, $order, 0);
-  $nodes = array();
-  $node_count = 1;
-  $options = array();
-  while ($node = db_fetch_object($result)) {
-    if (!isset($node->nodeorder)) {
-      $node->nodeorder = array();
-
-      // Store an element called 'nodeorder' that contains
-      // an associative array of tid to weight_in_tid...
-      $weights = db_query('SELECT tid, weight_in_tid FROM {term_node} WHERE nid = %d', $node->nid);
-      while ($term_node = db_fetch_object($weights)) {
-        $node->nodeorder[$term_node->tid] = $term_node->weight_in_tid;
-      }
-    }
-    
-    $nodes[] = $node;
-    $options[$node_count] = $node_count;
-    $node_count++;
-  }
-  
+  $node_ids = taxonomy_select_nodes($tid, TRUE, 50, array('t.weight' => 'ASC'));
+  $nodes = node_load_multiple($node_ids);
+  $node_count = count($nodes);
+
   // Weights range from -delta to +delta, so delta should be at least half
   // of the amount of blocks present. This makes sure all blocks in the same
   // region get an unique weight.
   $weight_delta = round($node_count / 2);
-  
-  $list_tr_id = 'node-sort-list-'. $tid;
+
   foreach ($nodes as $node) {
-    $key = $list_tr_id .'_'. $node->nid;
-  
-    $form[$key]['tid'] = array(
-      '#type' => 'value',
-      '#value' => $tid,
-    );
-    $form[$key]['nid'] = array(
-      '#type' => 'value',
-      '#value' => $node->nid,
-    );
-    $form[$key]['info'] =  array(
-      '#value' => check_plain($node->title),
-    );
-    $form[$key]['weight'] = array(
-      '#type' => 'select',
-      '#default_value' => $node->nodeorder[$tid],
-      '#options' => $options
+    $form[$node->nid]['#node'] = $node;
+    $form[$node->nid]['title'] = array(
+      '#markup' => check_plain($node->title));
+    $form[$node->nid]['weight'] = array(
+      '#type' => 'weight',
+      '#title' => t('Weight for @title', array('@title' => $node->title)),
+      '#title_display' => 'invisible',
+      '#delta' => 10,
+      '#default_value' => $node->weight,
     );
   }
-  
+
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Save order'),
-    '#disabled' => TRUE 
   );
-
   return $form;
 }
 
@@ -86,15 +60,15 @@ function nodeorder_admin_display_form(&$form_state, $tid) {
  * Process main blocks administration form submission.
  */
 function nodeorder_admin_display_form_submit($form, &$form_state) {
-  $sql = "UPDATE {term_node} SET weight_in_tid = %d WHERE tid = %d AND nid = %d";
-  $tid = -1;
+  $tid = $form['#term']->tid;
 
-  foreach ($form_state['values'] as $node) {
+  foreach ($form_state['values'] as $nid => $node) {
     // Only take form elements that are blocks.
-    if (is_array($node) && array_key_exists('tid', $node)) {
-      db_query($sql, $node['weight'], $node['tid'], $node['nid']);
-      
-      $tid = $node['tid'];
+    if (is_array($node) && array_key_exists('weight', $node)) {
+      db_update('taxonomy_index')->fields(array('weight' => $node['weight']))
+        ->condition('tid', $tid)
+        ->condition('nid', $nid)
+        ->execute();
     }
   }
 
@@ -105,28 +79,58 @@ function nodeorder_admin_display_form_submit($form, &$form_state) {
 }
 
 /**
- * Process variables for nodeorder-admin-display.tpl.php.
+ * Returns HTML for the vocabulary overview form as a sortable list of vocabularies.
  *
- * The $variables array contains the following arguments:
- * - $form
+ * @param $variables
+ *   An associative array containing:
+ *   - form: A render element representing the form.
  *
- * @see nodeorder-admin-display.tpl.php
- * @see theme_nodeorder_admin_display()
+ * @see taxonomy_overview_vocabularies()
+ * @ingroup themeable
  */
-function template_preprocess_nodeorder_admin_display_form(&$variables) { 
-  foreach (element_children($variables['form']) as $i) {
-    $node = &$variables['form'][$i];
-  
-    // Only take form elements that are nodes.
-    if (is_array($node) && array_key_exists('info', $node)) {
-      $variables['form'][$i]['weight']['#attributes']['class'] = 'nodeorder-weight';
-      $variables['node_listing'][$i]->row_class = isset($block['#attributes']['class']) ? $block['#attributes']['class'] : '';
-      $variables['node_listing'][$i]->node_title =  drupal_render($node['info']);
-      $variables['node_listing'][$i]->weight = drupal_render($node['weight']);
-      $variables['node_listing'][$i]->tid =  drupal_render($node['tid']);
-      $variables['node_listing'][$i]->nid =  drupal_render($node['nid']);
+function theme_nodeorder_admin_display_form($variables) {
+  $form = $variables['form'];
+
+  drupal_add_tabledrag('nodeorder', 'order', 'sibling', 'node-weight');
+
+  $errors = form_get_errors() != FALSE ? form_get_errors() : array();
+  $rows = array();
+  foreach (element_children($form) as $key) {
+    if (isset($form[$key]['#node'])) {
+      $node = &$form[$key];
+
+      $row = array();
+      $row[] = drupal_render($node['title']);
+      $node['weight']['#attributes']['class'] = array('node-weight');
+      $row[] = drupal_render($node['weight']);
+      $row = array('data' => $row);
+      $rows[$key] = $row;
+    }
+  }
+
+  // Add necessary classes to rows.
+  $row_position = 0;
+  foreach ($rows as $key => $row) {
+    $rows[$key]['class'] = array();
+    $rows[$key]['class'][] = 'draggable';
+
+    // Add an error class if this row contains a form error.
+    foreach ($errors as $error_key => $error) {
+      if (strpos($error_key, $key) === 0) {
+        $rows[$key]['class'][] = 'error';
+      }
     }
+    $row_position++;
   }
 
-  $variables['form_submit'] = drupal_render($variables['form']);
-}
\ No newline at end of file
+  if (empty($rows)) {
+    $rows[] = array(array('data' => $form['#empty_text'], 'colspan' => '3'));
+  }
+
+  $header = array(t('Title'), t('Weight'), );
+  $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'nodeorder')));
+  $output .= drupal_render_children($form);
+  $output .= theme('pager');
+
+  return $output;
+}
diff --git a/nodeorder.info b/nodeorder.info
index abdfe5c..5c37ba7 100644
--- a/nodeorder.info
+++ b/nodeorder.info
@@ -1,6 +1,3 @@
-name = "nodeorder"
+name = "Node Order"
 description = "Allows the ordering of nodes within taxonomy terms."
 core = 7.x
-files[] = nodeorder.module
-files[] = nodeorder.admin.inc
-files[] = nodeorder.install
diff --git a/nodeorder.install b/nodeorder.install
index f25e529..a05d640 100644
--- a/nodeorder.install
+++ b/nodeorder.install
@@ -4,15 +4,15 @@
  * @file
  * Nodeorder install file.
  */
- 
+
 /**
- * Implementation of hook_install()
+ * Implements hook_install().
  *
- * Adds field 'weight_in_tid' to core table 'term_node'.
+ * Adds field 'weight' to core table 'taxonomy_index'.
  */
 function nodeorder_install() {
   $module_name = 'nodeorder';
-  
+
   // Set field properties
   $spec =  array(
     'type' => 'int',
@@ -20,16 +20,16 @@ function nodeorder_install() {
     'not null' => TRUE,
     'default' => 0,
     'initial' => 0,
-    'description' => t('A user-defined weight for each node in its respective category.')
+    'description' => t('A user-defined weight for each node in its respective category.'),
   );
 
-  // Create an index for 'weight_in_tid'
-  $keys['indexes'] = array('weight_in_tid' => array('weight_in_tid'));
+  // Create an index for 'weight'
+  $keys['indexes'] = array('weight' => array('weight'));
 
   // Add the column to the table
   $ret = array();
-  db_add_field($ret, 'term_node', 'weight_in_tid', $spec, $keys);
-  
+  db_add_field('taxonomy_index', 'weight', $spec, $keys);
+
   // Check for query errors
   for ($i = 0; $i < count($ret); $i++) {
     if ($ret[$i]['success'] !== TRUE) {
@@ -37,7 +37,7 @@ function nodeorder_install() {
       break;
     }
   }
-  
+
   if ($installation_failed) {
     drupal_set_message(st('Table installation for the %name module was unsuccessful. The tables may need to be installed by hand.  See %name.install file for a list of the installation queries.', array('%name' => $module_name)), 'error');
   }
@@ -46,24 +46,32 @@ function nodeorder_install() {
     // so that we come after most other modules in module_invoke_all()
     // calls.  This ensures that we can alter forms after, for instance,
     // the taxonomy module...
-    db_query("UPDATE {system} SET weight = 5 WHERE name = 'nodeorder' AND type = 'module'");
-    
+    // TODO Please review the conversion of this statement to the D7 database API syntax.
+    /* db_query("UPDATE {system} SET weight = 5 WHERE name = 'nodeorder' AND type = 'module'") */
+    db_update('system')
+  ->fields(array(
+      'weight' => 5,
+    ))
+  ->condition('name', 'nodeorder')
+  ->condition('type', 'module')
+  ->execute();
+
     drupal_set_message(st('The %name module was installed successfully.', array('%name' => $module_name)));
   }
 }
 
 /**
- * Implementation of hook_uninstall()
+ * Implements hook_uninstall().
  *
- * Drops field 'weight_in_tid' from core table 'term_node'.
+ * Drops field 'weight' from core table 'taxonomy_index'.
  */
 function nodeorder_uninstall() {
   $module_name = 'nodeorder';
 
   $ret = array();
-  db_drop_index($ret, 'term_node', 'weight_in_tid');
-  db_drop_field($ret, 'term_node', 'weight_in_tid');
-  
+  db_drop_index('taxonomy_index', 'weight');
+  db_drop_field('taxonomy_index', 'weight');
+
   // Check for query errors
   for ($i = 0; $i < count($ret); $i++) {
     if ($ret[$i]['success'] !== TRUE) {
@@ -81,12 +89,12 @@ function nodeorder_uninstall() {
 }
 
 /**
- * Implementation of hook_schema_alter()
+ * Implements hook_schema_alter().
  *
- * Informs drupal_get_schema() of the field addition to 'term_node'.
+ * Informs drupal_get_schema() of the field addition to 'taxonomy_index'.
  */
 function nodeorder_schema_alter(&$schema) {
-  $schema['term_node']['fields']['weight_in_tid'] = array(
+  $schema['taxonomy_index']['fields']['weight'] = array(
     'type' => 'int',
     'signed' => TRUE,
     'not null' => TRUE,
@@ -94,33 +102,4 @@ function nodeorder_schema_alter(&$schema) {
     'initial' => 0,
     'description' => t('A user-defined weight for each node in its respective category.'),
   );
-}
-
-/**
- * Update function for Nodeorder-6.x-1.*
- * Original nodeorder schema used an unsigned field for the weight.
- * With the new ordering from core this should be changed to a signed field.
- * We therefore take the following measures:
- * - change the field to a signed field
- */
-function nodeorder_update_6100() {
-  $ret = array();
-
-  // Create an index for 'weight_in_tid'
-  $keys['indexes'] = array('weight_in_tid' => array('weight_in_tid'));
-
-  // Set field properties
-  $spec =  array(
-    'type' => 'int',
-    'signed' => TRUE,
-    'not null' => TRUE,
-    'default' => 0,
-    'initial' => 0,
-    'description' => t('A user-defined weight for each node in its respective category.')
-  );
-
-  // change field to a SIGNED int
-  db_change_field($ret, 'term_node', 'weight_in_tid', 'weight_in_tid', $spec, $keys);
-
-  return $ret;
-}
+}
\ No newline at end of file
diff --git a/nodeorder.js b/nodeorder.js
deleted file mode 100644
index b74814d..0000000
--- a/nodeorder.js
+++ /dev/null
@@ -1,16 +0,0 @@
-
-/**
- * Order nodes associated with a term.
- *
- * This behavior is dependent on the tableDrag behavior, since it uses the
- * objects initialized in that behavior to update the row.
- */
-Drupal.behaviors.blockDrag = function(context) {
-  var table = $('table#ordernodes');
-  var tableDrag = Drupal.tableDrag.ordernodes; // Get the blocks tableDrag object.
-
-  // Add a handler for when a row is swapped, enable the submit button.
-  tableDrag.onDrop = function() {
-    $('form#nodeorder-admin-display-form input#edit-submit').removeAttr('disabled');
-  };
-}
diff --git a/nodeorder.module b/nodeorder.module
index d00e3ae..1885e6f 100644
--- a/nodeorder.module
+++ b/nodeorder.module
@@ -7,54 +7,61 @@
  */
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_permission().
  */
-function nodeorder_perm() {
+function nodeorder_permission() {
   return array(
-    'order nodes within categories'
+    'order nodes within categories' => array(
+      'title' => t('order nodes within categories'),
+      'description' => t('TODO Add a description for \'order nodes within categories\''),
+    ),
   );
 }
 
 /**
- * Implementation of hook_theme()
+ * Implements hook_theme().
  */
 function nodeorder_theme() {
   return array(
     'nodeorder_admin_display_form' => array(
-      'template' => 'nodeorder-admin-display-form',
-      'arguments' => array('form' => NULL),
+      //'template' => 'nodeorder-admin-display-form',
+      'render element' => 'form',
       'file' => 'nodeorder.admin.inc',
     ),
   );
 }
 
 /**
- * Implementation of hook_form_alter().
+ * Implements hook_form_alter().
  */
 function nodeorder_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'taxonomy_form_vocabulary') {
     $is_orderable = $form['module']['#value'] == 'nodeorder';
-    
+
     $form['settings']['orderable'] = array(
       '#type' => 'checkbox',
       '#title' => t('Orderable'),
       '#description' => t('If enabled, nodes may be ordered within this vocabulary.'),
       '#weight' => 0.0075, // Try to have this show up after the 'Required' checkbox
-      '#default_value' => $is_orderable
+      '#default_value' => $is_orderable,
     );
-    
+
     // Add a submit handler for saving the orderable settings
     $form['#submit'][] = 'nodeorder_taxonomy_form_vocabulary_submit';
-    
+
     /*
-     * Why not implement hook_taxonomy? 
+     * Why not implement hook_taxonomy?
      *   hook_taxonomy sometimes gets called after editing terms;
-     *   in that case the orderable-value will not be available and thus the 
+     *   in that case the orderable-value will not be available and thus the
      *   orderable-setting on the vocabulary will always be disabled
      */
   }
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function nodeorder_taxonomy_form_vocabulary_submit($form, &$form_state) {
   $vid = $form_state['values']['vid'];
 
@@ -62,36 +69,45 @@ function nodeorder_taxonomy_form_vocabulary_submit($form, &$form_state) {
     if ($form_state['values']['module'] != 'nodeorder') {
       // Switching from non-orderable to orderable...
       cache_clear_all('nodeorder:', 'cache', TRUE);
-        
-      // Set weight_in_tid to nid for all rows in term_node where
+
+      // Set weight to nid for all rows in term_node where
       // the tid is in this vocabulary...
       $tree = taxonomy_get_tree($vid);
-        
+
       $tids = array();
-        
+
       foreach ($tree as $term) {
         $tids[] = $term->tid;
       }
-        
+
       if (count($tids) > 0) {
-        $order = 'n.sticky DESC, tn0.weight_in_tid';
-        $sql_max = "SELECT MAX(weight_in_tid) FROM {term_node} WHERE tid = %d";
-        $sql_update = "UPDATE {term_node} SET weight_in_tid = %d WHERE tid = %d AND nid = %d";
+        $order = 'n.sticky DESC, tn0.weight';
+        $sql_max = "SELECT MAX(weight) FROM {taxonomy_index} WHERE tid = %d";
+        $sql_update = "UPDATE {taxonomy_index} SET weight = %d WHERE tid = %d AND nid = %d";
 
         foreach ($tids as $i => $tid) {
           //select *current* nodes for the current term
           $result = nodeorder_select_nodes(array($tid), 'and', 0, FALSE, $order, 0);
-          
+
           while ($node = db_fetch_object($result)) {
-            db_lock_table('term_node');
-            $max = db_result(db_query($sql_max, $tid));
+            db_lock_table('taxonomy_term_node');
+            // TODO Please convert this statement to the D7 database API syntax.
+            $max = db_query($sql_max, $tid)->fetchField();
+            // TODO Please convert this statement to the D7 database API syntax.
             db_query($sql_update, $max + 1, $tid, $node->nid);
             db_unlock_tables();
           }
         }
       }
-        
-      db_query("UPDATE {vocabulary} SET module = '%s' WHERE vid = %d", 'nodeorder', $vid);
+
+      // TODO Please review the conversion of this statement to the D7 database API syntax.
+      /* db_query("UPDATE {taxonomy_vocabulary} SET module = '%s' WHERE vid = %d", 'nodeorder', $vid) */
+      db_update('taxonomy_vocabulary')
+  ->fields(array(
+        'module' => 'nodeorder',
+      ))
+  ->condition('vid', $vid)
+  ->execute();
 
       drupal_set_message(t('You may now order nodes within this vocabulary.'));
     }
@@ -100,30 +116,38 @@ function nodeorder_taxonomy_form_vocabulary_submit($form, &$form_state) {
     if ($form_state['values']['module'] == 'nodeorder') {
       // Switching from orderable to non-orderable...
       cache_clear_all('nodeorder:', 'cache', TRUE);
-      
-      db_query("UPDATE {vocabulary} SET module = '%s' WHERE vid = %d", 'taxonomy', $vid);
-        
-      // Set weight_in_tid to 0 for all rows in term_node where
+
+      // TODO Please review the conversion of this statement to the D7 database API syntax.
+      /* db_query("UPDATE {taxonomy_vocabulary} SET module = '%s' WHERE vid = %d", 'taxonomy', $vid) */
+      db_update('taxonomy_vocabulary')
+  ->fields(array(
+        'module' => 'taxonomy',
+      ))
+  ->condition('vid', $vid)
+  ->execute();
+
+      // Set weight to 0 for all rows in term_node where
       // the tid is in this vocabulary...
       $tree = taxonomy_get_tree($vid);
-        
+
       $tids = array();
-        
+
       foreach ($tree as $term) {
         $tids[] = $term->tid;
       }
-        
+
       if (count($tids) > 0) {
-        db_query("UPDATE {term_node} SET weight_in_tid = 0 WHERE tid IN (". implode(',', $tids) .")");
+        // TODO Please convert this statement to the D7 database API syntax.
+        db_query("UPDATE {taxonomy_index} SET weight = 0 WHERE tid IN (" . implode(',', $tids) . ")");
       }
-        
+
       drupal_set_message(t('You may no longer order nodes within this vocabulary.'));
     }
   }
 }
 
 /**
- * Implementation of hook_link().
+ * Implements hook_link().
  */
 function nodeorder_link($type, $node = 0, $main = 0) {
   $links = array();
@@ -135,10 +159,10 @@ function nodeorder_link($type, $node = 0, $main = 0) {
     if ($type == 'node') {
       if (array_key_exists('taxonomy', $node)) {
         $vocabularies = taxonomy_get_vocabularies();
-        
+
         if (variable_get('nodeorder_show_links_on_node', 1) == 2
-           && ((arg(0) == 'taxonomy' || arg(0) == 'nodeorder') && arg(1) == 'term')) {
-          $term = taxonomy_get_term(arg(2));
+            && ((arg(0) == 'taxonomy' || arg(0) == 'nodeorder') && arg(1) == 'term')) {
+          $term = taxonomy_term_load(arg(2));
           nodeorder_add_link($links, $vocabularies, $node, $term);
         }
         else if (variable_get('nodeorder_show_links_on_node', 1) == 1) {
@@ -153,63 +177,71 @@ function nodeorder_link($type, $node = 0, $main = 0) {
   return $links;
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function nodeorder_add_link(&$links, $vocabularies, $node, $term) {
   $vocabulary = $vocabularies[$term->vid];
-  
+
   if ($vocabulary->module == 'nodeorder') {
     $weights = nodeorder_get_term_min_max($term->tid, FALSE);
-    $weight = db_result(db_query("SELECT weight_in_tid FROM {term_node} WHERE nid = %d AND tid = %d", $node->nid, $term->tid));
-    
+    $weight = db_query("SELECT weight FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid", array(':nid' => $node->nid, ':tid' => $term->tid))->fetchField();
+
     if ($weight > $weights["min"]) {
-      $links['nodeorder_move_up_'. $term->tid] = array(
-        'href' => "nodeorder/moveup/". $node->nid ."/". $term->tid, 
-        'title' => t("move up in ". $term->name),
+      $links['nodeorder_move_up_' . $term->tid] = array(
+        'href' => "nodeorder/moveup/" . $node->nid . "/" . $term->tid,
+        'title' => t("move up in " . $term->name),
         'query' => drupal_get_destination(),
-        'attributes' => array('title' => t("Move this ". $node->type ." up in its category.")),
+        'attributes' => array('title' => t("Move this " . $node->type . " up in its category.")),
       );
     }
 
     if ($weight < $weights["max"]) {
-      $links['nodeorder_move_down_'. $term->tid] = array(
-        'href' => "nodeorder/movedown/". $node->nid ."/". $term->tid, 
-        'title' => t("move down in ". $term->name),
+      $links['nodeorder_move_down_' . $term->tid] = array(
+        'href' => "nodeorder/movedown/" . $node->nid . "/" . $term->tid,
+        'title' => t("move down in " . $term->name),
         'query' => drupal_get_destination(),
-        'attributes' => array('title' => t("Move this ". $node->type ." down in its category.")),
+        'attributes' => array('title' => t("Move this " . $node->type . " down in its category.")),
       );
     }
   }
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function nodeorder_get_term_min_max($tid, $reset) {
   static $min_weights = array();
   static $max_weights = array();
-  
+
   if ($reset) {
     unset($min_weights[$tid]);
     unset($max_weights[$tid]);
   }
 
   if (!$min_weights[$tid] || !$max_weights[$tid]) {
-    $result = db_query("SELECT tid, max(weight_in_tid) as max_weight, min(weight_in_tid) as min_weight FROM {term_node} WHERE tid = %d GROUP BY tid", $tid);
+    $result = db_query("SELECT tid, max(weight) as max_weight, min(weight) as min_weight FROM {taxonomy_index} WHERE tid = :tid GROUP BY tid", array(':tid' => $tid));
 
     while ($row = db_fetch_object($result)) {
       $min_weights[$row->tid] = $row->min_weight;
       $max_weights[$row->tid] = $row->max_weight;
     }
   }
-  
+
   $weights["min"] = $min_weights[$tid];
   $weights["max"] = $max_weights[$tid];
   return $weights;
 }
 
 /**
- * Implementation of hook_term_path() from Taxonomy.
+ * Implements hook_term_path() from Taxonomy().
  */
 function nodeorder_term_path($term) {
   if (variable_get('nodeorder_replace_taxonomy_link', 1)
-      || arg(0) == 'nodeorder') { //if nodeorder is being used to display term pages
-    return 'nodeorder/term/'. $term->tid;
+       || arg(0) == 'nodeorder') { //if nodeorder is being used to display term pages
+    return 'nodeorder/term/' . $term->tid;
   }
   else {
     return FALSE; //create regular taxonomy-links on taxonomy page
@@ -217,103 +249,60 @@ function nodeorder_term_path($term) {
 }
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function nodeorder_menu() {
   $items = array();
 
-    $items['admin/settings/nodeorder'] = array(
-      'title' => t('Nodeorder'),
-      'description' => t('Allows the ordering of nodes within taxonomy terms.'),
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('nodeorder_admin'),
-      'access arguments' => array('access administration pages'),
-      'type' => MENU_NORMAL_ITEM);
-    
-    $items['nodeorder/term/%'] = array(
-      'title' => t('Nodeorder term'),
-      'page callback' => 'nodeorder_term_page', // I want to call taxonomy_term_page but can't change the sort order...
-      'page arguments' => array(2),
-      'access arguments' => array('access content'),
-      'type' => MENU_CALLBACK);
-      
-    $items['nodeorder/order/%'] = array(
-      'title' => t('Order nodes'),
-      'page callback' => 'nodeorder_admin_display',
-      'page arguments' => array(2),
-      'access arguments' => array('order nodes within categories'),
-      'file' => 'nodeorder.admin.inc',
-      'type' => MENU_CALLBACK);
-
-    $items['taxonomy/term/%/view'] = array(
-      'title' => t('View'),
-      'page callback' => 'taxonomy_term_page',
-      'page arguments' => array(2),
-      'access arguments' => array('access content'),
-      'weight' => -10,
-      'type' => MENU_DEFAULT_LOCAL_TASK);
-    $items['taxonomy/term/%/order'] = array(
-      'title' => t('Order nodes'),
-      'page callback' => 'nodeorder_admin_display',
-      'page arguments' => array(2),
-      'access callback' => 'nodeorder_order_access',
-      'access arguments' => array(2),
-      'file' => 'nodeorder.admin.inc',
-      'weight' => 1,
-      'type' => MENU_LOCAL_TASK);
-      
-    $items['nodeorder/term/%/view'] = array(
-      'title' => t('View'),
-      'page callback' => 'nodeorder_term_page',
-      'page arguments' => array(2),
-      'access arguments' => array('access content'),
-      'weight' => -10,
-      'type' => MENU_DEFAULT_LOCAL_TASK);
-    $items['nodeorder/term/%/order'] = array(
-      'title' => t('Order nodes'),
-      'page callback' => 'nodeorder_admin_display',
-      'page arguments' => array(2),
-      'access callback' => 'nodeorder_order_access',
-      'access arguments' => array(2),
-      'file' => 'nodeorder.admin.inc',
-      'weight' => 1,
-      'type' => MENU_LOCAL_TASK);
-
-    $items['nodeorder/moveup/%/%'] = array(
-      'title' => t('Move Up'),
-      'page callback' => 'nodeorder_move_in_category',
-      'page arguments' => array(1, 2, 3),
-      'access arguments' => array('order nodes within categories'),
-      'type' => MENU_CALLBACK);
-    $items['nodeorder/movedown/%/%'] = array(
-      'title' => t('Move Down'),
-      'page callback' => 'nodeorder_move_in_category',
-      'page arguments' => array(1, 2, 3),
-      'access arguments' => array('order nodes within categories'),
-      'type' => MENU_CALLBACK);
-  
-    $items['admin/content/taxonomy/%/order'] = array(
-      'title' => t('Order nodes'),
-      'page callback' => 'nodeorder_overview_terms',
-      'page arguments' => array(3),
-      'access callback' => 'nodeorder_taxonomy_order_access',
-      'access arguments' => array(3),
-      'weight' => 5,
-      'type' => MENU_LOCAL_TASK);
+  $items['admin/config/nodeorder'] = array(
+    'title' => t('Nodeorder'),
+    'description' => t('Allows the ordering of nodes within taxonomy terms.'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('nodeorder_admin'),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  $items['taxonomy/term/%/order'] = array(
+    'title' => t('Order nodes'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('nodeorder_admin_display_form', 2),
+    'access callback' => 'nodeorder_order_access',
+    'access arguments' => array(2),
+    'file' => 'nodeorder.admin.inc',
+    'weight' => 1,
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['taxonomy/term/%taxonomy_term'] = array(
+    'title' => 'Taxonomy term',
+    'title callback' => 'taxonomy_term_title',
+    'title arguments' => array(2),
+    'page callback' => 'nodeorder_taxonomy_term_page',
+    'page arguments' => array(2),
+    'access arguments' => array('access content'),
+    'file' => 'nodeorder.pages.inc',
+  );
+  $items['taxonomy/term/%taxonomy_term/view'] = array(
+    'title' => 'View',
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+  );
   
+
   return $items;
 }
 
 /**
-* Custom access function which determines whether or not the user is allowed to reorder nodes and if the link should be shown at all
-*/
+ * Custom access function which determines whether or not the user is allowed to reorder nodes and if the link should be shown at all
+ */
 function nodeorder_order_access($tid) {
-  return user_access('order nodes within categories') && variable_get('nodeorder_link_to_ordering_page', 1) && nodeorder_term_can_be_ordered($tid);
+  return user_access('order nodes within categories') 
+    && variable_get('nodeorder_link_to_ordering_page', 1)
+    && nodeorder_term_can_be_ordered($tid);
 }
 
 /**
-* Custom access function which determines whether or not the user is allowed to reorder nodes and if the vocabulary is orderable
-*/
+ * Custom access function which determines whether or not the user is allowed to reorder nodes and if the vocabulary is orderable
+ */
 function nodeorder_taxonomy_order_access($vid) {
   return user_access('order nodes within categories') && variable_get('nodeorder_link_to_ordering_page_taxonomy_admin', 1) && nodeorder_vocabulary_can_be_ordered($vid);
 }
@@ -328,7 +317,8 @@ function nodeorder_term_page($str_tids = '', $depth = 0, $op = 'page') {
   }
 
   if ($terms['tids']) {
-    $result = db_query(db_rewrite_sql('SELECT t.tid, t.name FROM {term_data} t WHERE t.tid IN ('. db_placeholders($terms['tids']) .')', 't', 'tid'), $terms['tids']);
+    // TODO Please convert this statement to the D7 database API syntax.
+    $result = db_query(db_rewrite_sql('SELECT t.tid, t.name FROM {taxonomy_term_data} t WHERE t.tid IN (' . db_placeholders($terms['tids']) . ')', 't', 'tid'), $terms['tids']);
     $tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to.
     $names = array();
     while ($term = db_fetch_object($result)) {
@@ -337,20 +327,20 @@ function nodeorder_term_page($str_tids = '', $depth = 0, $op = 'page') {
     }
 
     if ($names) {
-      drupal_set_title($title = check_plain(implode(', ', $names)));
-      
+      drupal_set_title($title = implode(', ', $names));
+
       // Set the order that gets passed in to taxonomy_select_nodes.
       // This probably breaks down when there's a query that spans
       // multiple terms...
       //
-      // First sort by sticky, then by weight_in_tid...
+      // First sort by sticky, then by weight...
       if ($terms['operator'] == 'or') {
-        $order = 'n.sticky DESC, tn.weight_in_tid';
+        $order = 'n.sticky DESC, tn.weight';
       }
       else {
-        $order = 'n.sticky DESC, tn0.weight_in_tid';
+        $order = 'n.sticky DESC, tn0.weight';
       }
-      
+
       switch ($op) {
         case 'page':
           // Build breadcrumb based on first hierarchy of first term:
@@ -358,30 +348,31 @@ function nodeorder_term_page($str_tids = '', $depth = 0, $op = 'page') {
           $breadcrumb = array();
           while ($parents = taxonomy_get_parents($current->tid)) {
             $current = array_shift($parents);
-            $breadcrumb[] = l($current->name, 'nodeorder/term/'. $current->tid);
+            $breadcrumb[] = l($current->name, 'nodeorder/term/' . $current->tid);
           }
           $breadcrumb[] = l(t('Home'), NULL);
           $breadcrumb = array_reverse($breadcrumb);
           drupal_set_breadcrumb($breadcrumb);
-    
+
           module_load_include('inc', 'taxonomy', 'taxonomy.pages'); //.inc files are not loaded automatically
+          // TODO Please change this theme call to use an associative array for the $variables parameter.
           $output = theme('taxonomy_term_page', $tids, nodeorder_select_nodes($tids, $terms['operator'], $depth, TRUE, $order));
-           
-          drupal_add_feed(url('taxonomy/term/'. $str_tids .'/'. $depth .'/feed'), 'RSS - '. $title);
+
+          drupal_add_feed(url('taxonomy/term/' . $str_tids . '/' . $depth . '/feed'), 'RSS - ' . $title);
           return $output;
 
         case 'feed':
-          $channel['link'] = url('nodeorder/term/'. $str_tids .'/'. $depth, array('absolute' => TRUE));
-          $channel['title'] = variable_get('site_name', 'Drupal') .' - '. $title;
+          $channel['link'] = url('nodeorder/term/' . $str_tids . '/' . $depth, array('absolute' => TRUE));
+          $channel['title'] = variable_get('site_name', 'Drupal') . ' - ' . $title;
           // Only display the description if we have a single term, to avoid clutter and confusion.
           if (count($tids) == 1) {
-            $term = taxonomy_get_term($tids[0]);
+            $term = taxonomy_term_load($tids[0]);
             // HTML will be removed from feed description, so no need to filter here.
             $channel['description'] = $term->description;
           }
 
           $result = taxonomy_select_nodes($tids, $terms['operator'], $depth, FALSE, $order);
-          $items = array(); 
+          $items = array();
           while ($row = db_fetch_object($result)) {
             $items[] = $row->nid;
           }
@@ -402,7 +393,7 @@ function nodeorder_term_page($str_tids = '', $depth = 0, $op = 'page') {
  * NOTE: This is nearly a direct copy of taxonomy_select_nodes() -- see
  *       http://drupal.org/node/25801 if you find this sort of copy and
  *       paste upsetting...
- * 
+ *
  * Finds all nodes that match selected taxonomy conditions.
  *
  * @param $tids
@@ -434,33 +425,34 @@ function nodeorder_select_nodes($tids = array(), $operator = 'or', $depth = 0, $
       $depth = NULL;
     }
     foreach ($tids as $index => $tid) {
-      $term = taxonomy_get_term($tid);
-      $tree = taxonomy_get_tree($term->vid, $tid, -1, $depth);
+      $term = taxonomy_term_load($tid);
+      $tree = taxonomy_get_tree($term->vid, $tid, $depth);
       $descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree));
     }
 
     if ($operator == 'or') {
       $args = call_user_func_array('array_merge', $descendant_tids);
       $placeholders = db_placeholders($args, 'int');
-      $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created, tn.weight_in_tid FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid WHERE tn.tid IN ('. $placeholders .') AND n.status = 1 ORDER BY '. $order;
-      $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid WHERE tn.tid IN ('. $placeholders .') AND n.status = 1';
+      $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created, tn.weight FROM {node} n INNER JOIN {taxonomy_index} tn ON n.vid = tn.vid WHERE tn.tid IN (' . $placeholders . ') AND n.status = 1 ORDER BY ' . $order;
+      $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {taxonomy_index} tn ON n.vid = tn.vid WHERE tn.tid IN (' . $placeholders . ') AND n.status = 1';
     }
     else {
       $joins = '';
       $wheres = '';
       $args = array();
+      $query = db_select('node', 'n');
+      $query->condition('status', 1);
       foreach ($descendant_tids as $index => $tids) {
-        $joins .= ' INNER JOIN {term_node} tn'. $index .' ON n.vid = tn'. $index .'.vid';
-        $wheres .= ' AND tn'. $index .'.tid IN ('. db_placeholders($tids, 'int') .')';
-        $args = array_merge($args, $tids);
+        $query->join('taxonomy_term_node', "tn$index", "n.vid = tn{$index}.vid");
+        $query->condition("tn{$index}.tid", $tids, 'IN');
       }
-      $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created, tn0.weight_in_tid FROM {node} n '. $joins .' WHERE n.status = 1 '. $wheres .' ORDER BY '. $order;
-      $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. $joins .' WHERE n.status = 1 '. $wheres;
+      $query->fields('n', array('nid', 'sticky', 'title', 'created'));
+      // @todo: distinct?
+      $query->fields('tn0', array('weight'));
+      // @todo: ORDER BY ' . $order;
+      //$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n ' . $joins . ' WHERE n.status = 1 ' . $wheres;
     }
 
-    $sql = db_rewrite_sql($sql);
-    $sql_count = db_rewrite_sql($sql_count);
-
     if ($pager) {
       if ($count == -1) {
         $count = variable_get('default_nodes_main', 10);
@@ -471,12 +463,14 @@ function nodeorder_select_nodes($tids = array(), $operator = 'or', $depth = 0, $
       if ($count == -1) {
         $count = variable_get('feed_default_items', 10);
       }
-      
+
       if ($count == 0) {
-        $result = db_query($sql, $args);
+        // TODO Please convert this statement to the D7 database API syntax.
+        $result = $query->execute();
       }
       else {
-        $result = db_query_range($sql, $args, 0, $count);
+        // TODO Please convert this statement to the D7 database API syntax.
+        $result = db_query_range($sql, $args);
       }
     }
   }
@@ -489,14 +483,14 @@ function nodeorder_select_nodes($tids = array(), $operator = 'or', $depth = 0, $
  */
 function nodeorder_move_in_category($direction, $nid, $tid) {
   // Note that it would be nice to wrap this in a transaction...
-  
+
   $up = ($direction == 'moveup');
   $node = node_load($nid);
-  $destination = isset($_REQUEST['destination'])? $_REQUEST['destination']: $_GET['q'];
-  
+  $destination = isset($_GET['destination']) ? $_GET['destination'] : $_GET['q'];
+
   // Get the current weight for the node
-  $weight = db_result(db_query("SELECT weight_in_tid FROM {term_node} WHERE nid = %d AND tid = %d", $node->nid, $tid));
-  
+  $weight = db_query("SELECT weight FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid", array(':nid' => $node->nid, ':tid' => $tid))->fetchField();
+
   if ($up) {
     $weights = nodeorder_get_term_min_max($tid, FALSE);
     if ($weight == $weights["min"]) {
@@ -504,8 +498,8 @@ function nodeorder_move_in_category($direction, $nid, $tid) {
       drupal_goto($destination);
       return;
     }
-  
-    $sql = 'SELECT DISTINCT(n.nid), n.vid, tn.weight_in_tid FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid WHERE tn.tid = %d AND n.status = 1 AND tn.weight_in_tid <= %d ORDER BY tn.weight_in_tid DESC';
+
+    $sql = 'SELECT DISTINCT(n.nid), n.vid, tn.weight FROM {node} n INNER JOIN {taxonomy_index} tn ON n.vid = tn.vid WHERE tn.tid = %d AND n.status = 1 AND tn.weight <= %d ORDER BY tn.weight DESC';
     $direction = 'up';
   }
   else {
@@ -515,31 +509,47 @@ function nodeorder_move_in_category($direction, $nid, $tid) {
       drupal_goto($destination);
       return;
     }
-  
-    $sql = 'SELECT DISTINCT(n.nid), n.vid, tn.weight_in_tid FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid WHERE tn.tid = %d AND n.status = 1 AND tn.weight_in_tid >= %d ORDER BY tn.weight_in_tid';
+
+    $sql = 'SELECT DISTINCT(n.nid), n.vid, tn.weight FROM {node} n INNER JOIN {taxonomy_index} tn ON n.vid = tn.vid WHERE tn.tid = %d AND n.status = 1 AND tn.weight >= %d ORDER BY tn.weight';
     $direction = 'down';
   }
-  
-  $result = db_query_range($sql, $tid, $weight, 0, 2);
-  
+
+  $result = db_query_range('SELECT DISTINCT(n.nid), n.vid, tn.weight FROM {node} n INNER JOIN {taxonomy_index} tn ON n.vid = tn.vid WHERE tn.tid = :tn.tid AND n.status = :n.status AND tn.weight >= :tn.weight ORDER BY tn.weight', array(':tn.tid' => $tid, ':n.status' => 1, ':tn.weight' => $weight));
+
   $node1 = db_fetch_object($result);
   $node2 = db_fetch_object($result);
-  
+
   // Now we just need to swap the weights of the two nodes...
   if (!$node1 || !$node2) {
     drupal_set_message('There was a problem moving the node within its category.');
     drupal_access_denied();
     return;
   }
-  
-  $sql = "UPDATE {term_node} SET weight_in_tid = %d WHERE nid = %d AND tid = %d";
-  
-  db_query($sql, $node1->weight_in_tid, $node2->nid, $tid);
-  db_query($sql, $node2->weight_in_tid, $node1->nid, $tid);
 
-  $term = taxonomy_get_term($tid);
+  $sql = "UPDATE {taxonomy_index} SET weight = %d WHERE nid = %d AND tid = %d";
+
+  // TODO Please review the conversion of this statement to the D7 database API syntax.
+  /* db_query($sql, $node1->weight, $node2->nid, $tid) */
+  db_update('taxonomy_term_node')
+  ->fields(array(
+    'weight' => $node1->weight,
+  ))
+  ->condition('nid', $node2->nid)
+  ->condition('tid', $tid)
+  ->execute();
+  // TODO Please review the conversion of this statement to the D7 database API syntax.
+  /* db_query($sql, $node2->weight, $node1->nid, $tid) */
+  db_update('taxonomy_term_node')
+  ->fields(array(
+    'weight' => $node2->weight,
+  ))
+  ->condition('nid', $node1->nid)
+  ->condition('tid', $tid)
+  ->execute();
+
+  $term = taxonomy_term_load($tid);
   drupal_set_message(t("<em>%title</em> was moved $direction in %category...", array('%title' => $node->title, '%category' => $term->name)));
-  
+
   // Now send user to the page they were on before...
   drupal_goto($_GET['destination']);
 }
@@ -548,22 +558,23 @@ function nodeorder_move_in_category($direction, $nid, $tid) {
  * Returns TRUE if the node has terms in any orderable vocabulary...
  */
 function nodeorder_can_be_ordered($node) {
-  $cid = 'nodeorder:can_be_ordered:'. $node->type;
-  
+  $cid = 'nodeorder:can_be_ordered:' . $node->type;
+
   if (($cache = cache_get($cid)) && !empty($cache->data)) {
     return $cache->data;
-  } else {
-    $sql = "SELECT v.vid AS vid FROM {vocabulary_node_types} vnt JOIN {vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = '%s' AND v.module = 'nodeorder'";
-    $result = db_query($sql, $node->type);
+  }
+  else {
+    $sql = "SELECT v.vid AS vid FROM {taxonomy_vocabulary_node_type} vnt JOIN {taxonomy_vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = '%s' AND v.module = 'nodeorder'";
+    $result = db_query("SELECT v.vid AS vid FROM {taxonomy_vocabulary_node_type} vnt JOIN {taxonomy_vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = :vnt.type AND v.module = :v.module", array(':vnt.type' => $node->type, ':v.module' => 'nodeorder'));
 
     $can_be_ordered = FALSE;
     if (db_fetch_object($result)) {
       $can_be_ordered = TRUE;
     }
-    
+
     //permanently cache the value for easy reuse
     cache_set($cid, $can_be_ordered, 'cache');
-    
+
     return $can_be_ordered;
   }
 }
@@ -574,21 +585,22 @@ function nodeorder_can_be_ordered($node) {
 function nodeorder_orderable_tids($node) {
   $tids = array();
   $orderable_tids = array();
-  $cid = 'nodeorder:orderable_tids:'. $node->type;
-  
+  $cid = 'nodeorder:orderable_tids:' . $node->type;
+
   if (($cache = cache_get($cid)) && !empty($cache->data)) {
     $orderable_tids = $cache->data;
-  } else {
-    $sql = "SELECT v.vid AS vid FROM {vocabulary_node_types} vnt JOIN {vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = '%s' AND v.module = 'nodeorder'";
-    $result = db_query($sql, $node->type);
-  
+  }
+  else {
+    $sql = "SELECT v.vid AS vid FROM {taxonomy_vocabulary_node_type} vnt JOIN {taxonomy_vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = '%s' AND v.module = 'nodeorder'";
+    $result = db_query("SELECT v.vid AS vid FROM {taxonomy_vocabulary_node_type} vnt JOIN {taxonomy_vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = :vnt.type AND v.module = :v.module", array(':vnt.type' => $node->type, ':v.module' => 'nodeorder'));
+
     while ($row = db_fetch_object($result)) {
       $tree = taxonomy_get_tree($row->vid);
       foreach ($tree as $term) {
         $orderable_tids[] = $term->tid;
       }
     }
-    
+
     //permanently cache the value for easy reuse
     cache_set($cid, $orderable_tids, 'cache');
   }
@@ -596,13 +608,17 @@ function nodeorder_orderable_tids($node) {
   // Now select only those tids which are actually assigned to this term
   foreach ($node->taxonomy as $key => $value) {
     $list_of_tids = nodeorder_get_tids($key, $value);
-    
+
     $tids = array_merge($tids, array_intersect($list_of_tids, $orderable_tids));
   }
 
   return $tids;
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function nodeorder_get_tids($key, $value) {
   $tids = array();
 
@@ -622,9 +638,10 @@ function nodeorder_get_tids($key, $value) {
     }
     else if (is_string($value)) {
       $values = drupal_explode_tags($value);
-      $get_tid_sql = "SELECT tid FROM {term_data} WHERE name = '%s' AND vid = %d";
+      $get_tid_sql = "SELECT tid FROM {taxonomy_term_data} WHERE name = '%s' AND vid = %d";
       foreach ($values as $term_name) {
-        $tids[] = db_result(db_query($get_tid_sql, $term_name, $key));
+        // TODO Please convert this statement to the D7 database API syntax.
+        $tids[] = db_query($get_tid_sql, $term_name, $key)->fetchField();
       }
     }
   }
@@ -636,13 +653,13 @@ function nodeorder_get_tids($key, $value) {
  * Returns TRUE if the vocabulary is orderable...
  */
 function nodeorder_vocabulary_can_be_ordered($vid) {
-  $sql = "SELECT * FROM {vocabulary} WHERE module = 'nodeorder' AND vid = %d";
-  $result = db_query($sql, $vid);
-  
-  if (db_fetch_object($result)) {
+  $sql = "SELECT * FROM {taxonomy_vocabulary} WHERE module = 'nodeorder' AND vid = %d";
+  $result = db_query("SELECT * FROM {taxonomy_vocabulary} WHERE module = :module AND vid = :vid", array(':module' => 'nodeorder', ':vid' => $vid));
+
+  if ($result->fetchAssoc()) {
     return TRUE;
   }
-  
+
   return FALSE;
 }
 
@@ -650,107 +667,132 @@ function nodeorder_vocabulary_can_be_ordered($vid) {
  * Returns TRUE if the term is in an orderable vocabulary...
  */
 function nodeorder_term_can_be_ordered($tid) {
-  $cid = 'nodeorder:term_can_be_ordered:'. $tid;
-  
+  return TRUE;
+  // @todo: perform real check
+  $cid = 'nodeorder:term_can_be_ordered:' . $tid;
+
   if (($cache = cache_get($cid)) && !empty($cache->data)) {
     return $cache->data;
-  } else {
-    $sql = "SELECT vid FROM {term_data} WHERE tid = %d";
-    $vid = db_result(db_query($sql, $tid));
-  
-    $sql = "SELECT * FROM {vocabulary} WHERE module = 'nodeorder' AND vid = %d";
-    $result = db_query($sql, $vid);
+  }
+  else {
+    $sql = "SELECT vid FROM {taxonomy_term_data} WHERE tid = %d";
+    $vid = db_query("SELECT vid FROM {taxonomy_term_data} WHERE tid = :tid", array(':tid' => $tid))->fetchField();
+
+    $sql = "SELECT * FROM {taxonomy_vocabulary} WHERE module = 'nodeorder' AND vid = %d";
+    $result = db_query("SELECT * FROM {taxonomy_vocabulary} WHERE module = :module AND vid = :vid", array(':module' => 'nodeorder', ':vid' => $vid));
 
-    $term_can_be_ordered = FALSE;
+    // @todo: make real check
+    $term_can_be_ordered = TRUE;
     if (db_fetch_object($result)) {
       $term_can_be_ordered = TRUE;
     }
-    
+
     //permanently cache the value for easy reuse
     cache_set($cid, $term_can_be_ordered, 'cache');
-    
+
     return $term_can_be_ordered;
   }
 }
 
 /**
- * Implementation of hook_nodeapi().
+ * Implements hook_node_presave().
  */
-function nodeorder_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
-  switch ($op) {
-    case 'presave':
-      if (nodeorder_can_be_ordered($node)) {    
-        if (!isset($node->nodeorder)) {
-          $node->nodeorder = array();
-  
-          // When a node gets loaded, store an element called 'nodeorder' that contains
-          // an associative array of tid to weight_in_tid...
-          $result = db_query('SELECT tid, weight_in_tid FROM {term_node} WHERE nid = %d', $node->nid);
-          while ($term_node = db_fetch_object($result)) {
-            $node->nodeorder[$term_node->tid] = $term_node->weight_in_tid;
-          }
-        }
+function nodeorder_node_presave($node) {
+  if (nodeorder_can_be_ordered($node)) {
+    if (!isset($node->nodeorder)) {
+      $node->nodeorder = array();
+
+      // When a node gets loaded, store an element called 'nodeorder' that contains
+      // an associative array of tid to weight...
+      $result = db_query('SELECT tid, weight FROM {taxonomy_index} WHERE nid = :nid', array(':nid' => $node->nid));
+      while ($term_node = db_fetch_object($result)) {
+        $node->nodeorder[$term_node->tid] = $term_node->weight;
       }
-      break;
-    case 'delete':
-      // make sure the weight cache is invalidated
-      if (nodeorder_can_be_ordered($node)) {
-        $tids = nodeorder_orderable_tids($node);
-  
-        if (count($tids) > 0) {
-          foreach ($tids as $i => $tid) {
-            nodeorder_get_term_min_max($tid, TRUE); // reinitialize the cache
-          }
-        }
+    }
+  }
+}
+
+/**
+ * Implements hook_node_delete().
+ */
+function nodeorder_node_delete($node) {
+  // make sure the weight cache is invalidated
+  if (nodeorder_can_be_ordered($node)) {
+    $tids = nodeorder_orderable_tids($node);
+
+    if (count($tids) > 0) {
+      foreach ($tids as $i => $tid) {
+        nodeorder_get_term_min_max($tid, TRUE); // reinitialize the cache
       }
-      break;
-    case 'insert':
-      // Set the initial weight_in_tid to max+1... This makes sure that the weight
-      // will be unique for each nid/tid combination
-      //
-      // NOTE - fall through to 'update' since we do mostly the same thing there.
-    case 'update':
-      // Set the weight_in_tid -- taxonomy probably stomped it because
-      // we added the weight_in_tid column to term_node, and taxonomy
-      // just wants to delete and re-insert rows when things change...
-      
-      // Note that we only want to set the weight_in_tid for tids that
-      // are in orderable vocabularies...
-      if (nodeorder_can_be_ordered($node)) {
-        $tids = nodeorder_orderable_tids($node);
-  
-        if (count($tids) > 0) {
-          $sql = "UPDATE {term_node} SET weight_in_tid = %d WHERE tid = %d AND nid = %d";
-  
-          foreach ($tids as $i => $tid) {
-            db_lock_table('term_node');
-            $weights = nodeorder_get_term_min_max($tid, FALSE); // get the cached weights
-            db_query($sql, $weights["max"] + 1, $tid, $node->nid);
-            nodeorder_get_term_min_max($tid, TRUE); // reinitialize the cache
-            db_unlock_tables();
-          }
-        }
-        
-        // New nodes won't have any saved weight_in_tid values so this array will be empty...
-        if ($node->nodeorder) {
-          // Restore any saved weight_in_tid values...
-          $sql = "UPDATE {term_node} SET weight_in_tid = %d WHERE nid = %d AND tid = %d";
-          foreach ($node->nodeorder as $tid => $weight_in_tid) {
-            // weight_in_tid cannot be 0
-            if ($weight_in_tid != 0) {
-              db_query($sql, $weight_in_tid, $node->nid, $tid);
-            }
-          }
+    }
+  }
+}
+
+/**
+ * Implements hook_node_insert().
+ */
+function nodeorder_node_insert($node) {
+  // Set the initial weight to max+1... This makes sure that the weight
+  // will be unique for each nid/tid combination
+  //
+  // NOTE - fall through to 'update' since we do mostly the same thing there.
+}
+
+/**
+ * Implements hook_node_load().
+ */
+function nodeorder_node_load(&$nodes) {
+  $result = db_query('SELECT weight FROM {taxonomy_index} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes)));
+  foreach ($result as $record) {
+    $nodes[$record->nid]->weight = $record->weight;
+  }
+}
+
+/**
+ * Implements hook_node_update().
+ */
+function nodeorder_node_update($node) {
+  // Set the weight -- taxonomy probably stomped it because
+  // we added the weight column to term_node, and taxonomy
+  // just wants to delete and re-insert rows when things change...
+
+  // Note that we only want to set the weight for tids that
+  // are in orderable vocabularies...
+  if (nodeorder_can_be_ordered($node)) {
+    $tids = nodeorder_orderable_tids($node);
+
+    if (count($tids) > 0) {
+      $sql = "UPDATE {taxonomy_index} SET weight = %d WHERE tid = %d AND nid = %d";
+
+      foreach ($tids as $i => $tid) {
+        db_lock_table('taxonomy_term_node');
+        $weights = nodeorder_get_term_min_max($tid, FALSE); // get the cached weights
+        // TODO Please convert this statement to the D7 database API syntax.
+        db_query($sql, $weights["max"] + 1, $tid, $node->nid);
+        nodeorder_get_term_min_max($tid, TRUE); // reinitialize the cache
+        db_unlock_tables();
+      }
+    }
+
+    // New nodes won't have any saved weight values so this array will be empty...
+    if ($node->nodeorder) {
+      // Restore any saved weight values...
+      $sql = "UPDATE {taxonomy_index} SET weight = %d WHERE nid = %d AND tid = %d";
+      foreach ($node->nodeorder as $tid => $weight) {
+        // weight cannot be 0
+        if ($weight != 0) {
+          // TODO Please convert this statement to the D7 database API syntax.
+          db_query($sql, $weight, $node->nid, $tid);
         }
       }
-      break;
+    }
   }
 }
 
 /**
  * Form for Admin Settings
  */
-function nodeorder_admin() {
+function nodeorder_admin($form, &$form_state) {
   $form['nodeorder_show_links'] = array(
     '#type' => 'fieldset',
     '#title' => t('Display ordering links'),
@@ -768,48 +810,52 @@ function nodeorder_admin() {
     '#type' => 'checkbox',
     '#title' => t('Display link to the ordering page'),
     '#description' => t('If enabled, a tab will appear on all <em>nodeorder/term/%</em> and <em>taxonomy/term/%</em> pages that quickly allows administrators to get to the node ordering administration page for the term.'),
-    '#default_value' => variable_get('nodeorder_link_to_ordering_page', 1)
+    '#default_value' => variable_get('nodeorder_link_to_ordering_page', 1),
   );
-  
+
   $form['nodeorder_link_to_ordering_page_taxonomy_admin'] = array(
     '#type' => 'checkbox',
     '#title' => t('Display link to the ordering page on taxonomy administration page'),
     '#description' => t('If enabled, a tab will appear on <em>admin/content/taxonomy/%</em> pages that quickly allows administrators to get to the node ordering administration page for the term.'),
-    '#default_value' => variable_get('nodeorder_link_to_ordering_page_taxonomy_admin', 1)
+    '#default_value' => variable_get('nodeorder_link_to_ordering_page_taxonomy_admin', 1),
   );
-  
+
   $form['nodeorder_replace_taxonomy_link'] = array(
     '#type' => 'checkbox',
     '#title' => t('Replace the link to <em>taxonomy/term/%</em> by <em>nodeorder/term/%</em>'),
     '#description' => t('If enabled, links to regular <em>taxonomy/term/%</em> pages will always be replaced by links to their <em>nodeorder/term/%</em> counterpart. Otherwise, this will only happen on the <em>nodeorder/term/%</em> pages.'),
-    '#default_value' => variable_get('nodeorder_replace_taxonomy_link', 1)
+    '#default_value' => variable_get('nodeorder_replace_taxonomy_link', 1),
   );
-  
-  
+
+
   return system_settings_form($form);
 }
 
 /**
  * Display a tree of all the terms in a vocabulary, with options to
  * order nodes within each one.
- * 
+ *
  * This code was cut and pasted from taxonomy_overview_terms.  If
  * If we were able to add another operation onto each term on the
  * admin/content/taxonomy/VID page then we wouldn't even need this duplicate
  * function.
- * 
+ *
  * TODO - put in a patch for a taxonomy hook that lets us add
  *        admin operation links per term...  maybe it would call
  *        module_invoke_all('taxonomy', 'list', 'term', $term) and
  *        array_merge the results with each $row[]...
  */
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function nodeorder_overview_terms($vid) {
   if (!nodeorder_vocabulary_can_be_ordered($vid)) {
     return t('This vocabulary is not orderable.  If you would like it to be orderable, check the Orderable box ') .
-      l(t('here'), 'admin/content/taxonomy/edit/vocabulary'. $vid) .'.'; 
+      l(t('here'), 'admin/structure/taxonomy/edit/vocabulary' . $vid) . '.';
   }
-  
+
   $header = array(t('Name'), t('Operations'));
   $vocabularies = taxonomy_get_vocabularies();
   $vocabulary = $vocabularies[$vid];
@@ -817,11 +863,11 @@ function nodeorder_overview_terms($vid) {
     return drupal_not_found();
   }
 
-  drupal_set_title(t('Terms in %vocabulary', array('%vocabulary' => $vocabulary->name)));
+  drupal_set_title(t('Terms in %vocabulary', array('%vocabulary' => $vocabulary->name)), PASS_THROUGH);
   $start_from      = $_GET['page'] ? $_GET['page'] : 0;
-  $total_entries   = 0;  // total count for pager
+  $total_entries   = 0; // total count for pager
   $page_increment  = 25; // number of tids per page
-  $displayed_count = 0;  // number of tids shown
+  $displayed_count = 0; // number of tids shown
 
   $tree = taxonomy_get_tree($vocabulary->vid);
   foreach ($tree as $term) {
@@ -829,30 +875,36 @@ function nodeorder_overview_terms($vid) {
     if (($start_from && ($start_from * $page_increment) >= $total_entries) || ($displayed_count == $page_increment)) {
       continue;
     }
-    $rows[] = array((isset($term->depth) && $term->depth > 0 ? theme('indentation', $term->depth) : '') . l($term->name, "nodeorder/term/$term->tid"), l(t('order nodes'), "nodeorder/term/$term->tid/order"));
+    $rows[] = array((isset($term->depth) && $term->depth > 0 ? theme('indentation', array('size' => $term->depth)) : '') . l($term->name, "nodeorder/term/$term->tid"), l(t('order nodes'), "nodeorder/term/$term->tid/order"));
     $displayed_count++; // we're counting tids displayed
   }
 
   if (!$rows) {
-    $rows[] = array(array('data' => t('No terms available.'), 'colspan' => '2'));
+    $rows[] = array(array(
+        'data' => t('No terms available.'),
+        'colspan' => '2',
+      ));
   }
 
-  $GLOBALS['pager_page_array'][] = $start_from;  // FIXME
+  $GLOBALS['pager_page_array'][] = $start_from; // FIXME
   $GLOBALS['pager_total'][] = intval($total_entries / $page_increment) + 1; // FIXME
 
   if ($total_entries >= $page_increment) {
-    $rows[] = array(array('data' => theme('pager', NULL, $page_increment), 'colspan' => '2'));
+    $rows[] = array(array(
+        'data' => theme('pager', array('tags' => NULL)),
+        'colspan' => '2',
+      ));
   }
 
-  return theme('table', $header, $rows, array('id' => 'taxonomy'));
+  return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'taxonomy')));
 }
 
 /**
- * Implementation of hook_views_data_alter().
+ * Implements hook_views_data_alter().
  */
 function nodeorder_views_data_alter(&$data) {
   // taxonomy weight
-  $data['term_node']['weight_in_tid'] = array(
+  $data['taxonomy_term_node']['weight'] = array(
     'title' => t('Weight in tid'),
     'help' => t('The term weight in tid field'),
     'field' => array(
@@ -866,20 +918,20 @@ function nodeorder_views_data_alter(&$data) {
 }
 
 /**
- * Implementation of hook_help().
+ * Implements hook_help().
  */
 function nodeorder_help($path, $arg) {
   switch ($path) {
     case 'nodeorder/term/%/order':
     case 'nodeorder/order/%':
-      $term = taxonomy_get_term($arg[2]);
-      $output = '<p>'. t('This page provides a drag-and-drop interface for ordering nodes. To change the order of a node, grab a drag-and-drop handle under the <em>Node title</em> column and drag the node to a new location in the list. (Grab a handle by clicking and holding the mouse while hovering over a handle icon.) Remember that your changes will not be saved until you click the <em>Save order</em> button at the bottom of the page.') .'</p>';
-    
+      $term = taxonomy_term_load($arg[2]);
+      $output = '<p>' . t('This page provides a drag-and-drop interface for ordering nodes. To change the order of a node, grab a drag-and-drop handle under the <em>Node title</em> column and drag the node to a new location in the list. (Grab a handle by clicking and holding the mouse while hovering over a handle icon.) Remember that your changes will not be saved until you click the <em>Save order</em> button at the bottom of the page.') . '</p>';
+
       return $output;
-    case 'admin/content/taxonomy/%/order':
+    case 'admin/structure/taxonomy/%/order':
       $vocabulary = taxonomy_vocabulary_load($arg[3]);
-      $output = '<p>'. t('%capital_name is an orderable vocabulary. You may order the nodes associated with a term within this vocabulary by clicking the <em>order nodes</em> link next to the term.', array('%capital_name' => drupal_ucfirst($vocabulary->name)));
-      
+      $output = '<p>' . t('%capital_name is an orderable vocabulary. You may order the nodes associated with a term within this vocabulary by clicking the <em>order nodes</em> link next to the term.', array('%capital_name' => drupal_ucfirst($vocabulary->name)));
+
       return $output;
   }
 }
diff --git a/nodeorder.pages.inc b/nodeorder.pages.inc
new file mode 100644
index 0000000..9608d95
--- /dev/null
+++ b/nodeorder.pages.inc
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Menu callback; displays all nodes associated with a term.
+ *
+ * @param $term
+ *   The taxonomy term.
+ * @return
+ *   The page content.
+ */
+function nodeorder_taxonomy_term_page($term) {
+  // Assign the term name as the page title.
+  drupal_set_title($term->name);
+
+  // Build breadcrumb based on the hierarchy of the term.
+  $current = (object) array(
+    'tid' => $term->tid,
+  );
+  // @todo This overrides any other possible breadcrumb and is a pure hard-coded
+  //   presumption. Make this behavior configurable per vocabulary or term.
+  $breadcrumb = array();
+  while ($parents = taxonomy_get_parents($current->tid)) {
+    $current = array_shift($parents);
+    $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
+  }
+  $breadcrumb[] = l(t('Home'), NULL);
+  $breadcrumb = array_reverse($breadcrumb);
+  drupal_set_breadcrumb($breadcrumb);
+  drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);
+
+  $build = array();
+
+  $build['term_heading'] = array(
+    '#prefix' => '<div class="term-listing-heading">',
+    '#suffix' => '</div>',
+    'term' => taxonomy_term_view($term, 'full'),
+  );
+
+  if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10),
+    array('t.weight' => 'ASC'))) {
+    $nodes = node_load_multiple($nids);
+    $build += node_view_multiple($nodes);
+    $build['pager'] = array(
+      '#theme' => 'pager',
+      '#weight' => 5,
+     );
+  }
+  else {
+    $build['no_content'] = array(
+      '#prefix' => '<p>',
+      '#markup' => t('There is currently no content classified with this term.'),
+      '#suffix' => '</p>',
+    );
+  }
+  return $build;
+}
