diff --git a/similarterms.info b/similarterms.info
index bdd2650..36e5cfc 100644
--- a/similarterms.info
+++ b/similarterms.info
@@ -1,5 +1,9 @@
-core = "6.x"
-dependencies[] = "views"
-description = "Use Views to show similar content based on taxonomy terms"
 name = "Similar By Terms"
+description = "Use Views to show similar content based on taxonomy terms"
+core = 7.x
+dependencies[] = "views"
 package = "Views"
+files[] = similarterms.test
+files[] = views/similarterms_handler_argument_node_nid.inc
+files[] = views/similarterms_handler_field_similar.inc
+files[] = views/similarterms_handler_sort_similar.inc
diff --git a/similarterms.install b/similarterms.install
old mode 100644
new mode 100755
index c56aef3..1e5882c
--- a/similarterms.install
+++ b/similarterms.install
@@ -1,19 +1,28 @@
 <?php
+/**
+ * @file
+ * Install, update and uninstall functions for the similarterms module.
+ *
+ */
+
 
 
 /**
- * Implementation of hook_update().
+ * Implements hook_update().
  */
 function similarterms_update_6200() {
   $ret = array();
-  
+
   // Intentially removed to prevent confusion.
   //   I don't want administrators to think that their settings have been converted.
-  
-  // only the 'ANY vocabulary' block is converted... without any settings: 
-  //$ret[] = update_sql("UPDATE {blocks} SET module='views', delta='similarterms-block_1' WHERE module='similarterms' AND delta=0");
-  
+
+  // only the 'ANY vocabulary' block is converted... without any settings:
+  //$ret[] = update_sql("UPDATE {block} SET module='views', delta='similarterms-block_1' WHERE module='similarterms' AND delta=0");
+
   cache_clear_all('*', 'cache_block', TRUE);
   cache_clear_all('*', 'cache_views', true);
-  return $ret;
+  // hook_update_N() no longer returns a $ret array. Instead, return
+  // nothing or a translated string indicating the update ran successfully.
+  // See http://drupal.org/node/224333#update_sql.
+  return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
 }
diff --git a/similarterms.module b/similarterms.module
old mode 100644
new mode 100755
index b40d1a2..9cdf8ea
--- a/similarterms.module
+++ b/similarterms.module
@@ -1,12 +1,12 @@
 <?php
 
 /**
-  * Implementation of hook_views_api.
-  * Notifies the Views module that we're compatible with a particular API revision.
-  */
+ * Implements hook_views_api().
+ * Notifies the Views module that we're compatible with a particular API revision.
+ */
 function similarterms_views_api() {
   return array(
-    'api' => 2,
+    'api' => 3,
     'path' => drupal_get_path('module', 'similarterms') . '/views',
   );
-}
\ No newline at end of file
+}
diff --git a/similarterms.test b/similarterms.test
new file mode 100755
index 0000000..96d33e8
--- /dev/null
+++ b/similarterms.test
@@ -0,0 +1,303 @@
+<?php
+
+/**
+ * @file
+ * Definition of similarTermsTestCase.
+ *
+ * @todo
+ * - Test the vocbular option in the argument handler.
+ * - Test the field_similar, sort_similar handler.
+ */
+
+/**
+ * Tests functionality of similar terms module.
+ */
+class similarTermsTestCase extends TaxonomyWebTestCase {
+  /**
+   * Stores all nids.
+   * @var array
+   */
+  public $nids;
+
+  /**
+   * Stores all tids.
+   * @var array
+   */
+  public $tids;
+
+  /**
+   * Stores all node-id's keyed by tid.
+   * @var array
+   */
+  public $nodes_per_term;
+
+  /**
+   * Contains the used vocabulary.
+   */
+  public $vocabulary;
+  public $node_type;
+  public $field;
+  public $field_name;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Similarterms',
+      'description' => 'Test the Similarterms module',
+      'group' => 'Similarterms',
+    );
+  }
+  protected function setUp() {
+    parent::setUp('views', 'taxonomy', 'node', 'similarterms');
+
+    // Create a vocabulary and some terms.
+    $this->vocabulary = $this->createVocabulary();
+    for ($i = 0; $i < 3; $i++) {
+      $term = $this->createTerm($this->vocabulary);
+      $this->tids[] = $term->tid;
+    }
+
+    // Create a nodetype and attach a taxonomy field to it.
+    $this->node_type = $this->drupalCreateContentType();
+    $this->field_name = 'field_test_taxonomy';
+    $this->field = array(
+      'field_name' => $this->field_name,
+      'type' => 'taxonomy_term_reference',
+      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+      'settings' => array(
+        'allowed_values' => array(
+          array(
+            'vocabulary' => $this->vocabulary->machine_name,
+            'parent' => 0,
+          ),
+        ),
+      ),
+    );
+    field_create_field($this->field);
+    $this->instance = array(
+      'field_name' => $this->field_name,
+      'bundle' => $this->node_type->type,
+      'entity_type' => 'node',
+      'widget' => array(
+        'type' => 'options_select',
+      ),
+      'display' => array(
+        'default' => array(
+          'type' => 'taxonomy_term_reference_link',
+        ),
+      ),
+    );
+    field_create_instance($this->instance);
+
+
+    // Create the used nodes.
+    // First create a node with a term which is not used by other nodes.
+    $this->createNodeWithTerm($this->tids[0]);
+    // Create a node with a term which is is used by the third node as well.
+    $this->createNodeWithTerm($this->tids[1]);
+    // The third node should have the term of the second and forth.
+    $this->createNodeWithTerm(array($this->tids[1], $this->tids[2]));
+    $this->createNodeWithTerm(array($this->tids[2]));
+  }
+
+  /**
+   * Create a node with certain terms.
+   * @param array $tids
+   *   An array of all taxonomy terms.
+   * @param array $edit
+   *   The edit array @see DrupalWebTestCase::drupalCreateNode.
+   */
+  public function createNodeWithTerm($tids, array $edit = array()) {
+    $tids = (array) $tids;
+    if (!isset($edit['type'])) {
+      $edit['type'] = $this->node_type->type;
+    }
+    foreach ($tids as $tid) {
+      $edit[$this->field_name][LANGUAGE_NONE][] = array('tid' => $tid);
+    }
+
+    $node = $this->drupalCreateNode($edit);
+    $this->nids[] = $node->nid;
+    foreach ($tids as $tid) {
+      $this->nodes_per_term[$tid][] = $node->nid;
+    }
+  }
+
+  function testSimilarTerms() {
+    $nid_alias = 'node_nid';
+
+    foreach ($this->nids as $nid) {
+      $node = node_load($nid);
+      $view = $this->viewSimilarTerms();
+      $view->set_display();
+      $view->pre_execute(array($nid));
+      $view->execute();
+      switch ($nid) {
+        case 1:
+          $this->assertEqual(count($view->result), 0, "Take sure that a node without a similar term doesn't generate a view result");
+          break;
+        case 2:
+          $this->assertEqual(count($view->result), 1, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array($nid_alias => 3)));
+          break;
+
+        case 3:
+          $this->assertEqual(count($view->result), 2, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array($nid_alias => 2), array($nid_alias => 4)));
+          break;
+
+        case 4:
+          $this->assertEqual(count($view->result), 1, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array($nid_alias => 4)));
+          break;
+
+      }
+
+      $view->destroy();
+    }
+  }
+
+  function testSimilarTermsIncludeArgs() {
+    foreach ($this->nids as $nid) {
+      $node = node_load($nid);
+      $view = $this->viewSimilarTerms();
+      $view->set_display();
+      $view->pre_execute(array($nid));
+      $view->argument['nid']->options['include_args'] = TRUE;
+      $view->execute();
+      switch ($nid) {
+        case 1:
+          $this->assertEqual(count($view->result), 1, "Take sure that a node without a similar term doesn't generate a view result");
+          $this->assertIdenticalResultset($view, array(array('nid' => 1)), array('node_nid' => 'nid'));
+          break;
+        case 2:
+          $this->assertEqual(count($view->result), 2, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array('nid' => 2), array('nid' => 3)), array('node_nid' => 'nid'));
+          break;
+
+        case 3:
+          $this->assertEqual(count($view->result), 3, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array('nid' => 2), array('nid' => 3), array('nid' => 4)), array('node_nid' => 'nid'));
+          break;
+
+        case 4:
+          $this->assertEqual(count($view->result), 2, "Take sure that the right amount of result are returned");
+          $this->assertIdenticalResultset($view, array(array('nid' => 3), array('nid' => 4)), array('node_nid' => 'nid'));
+          break;
+
+      }
+
+      $view->destroy();
+    }
+  }
+
+  public function viewSimilarTerms() {
+    $view = new view;
+    $view->name = 'test_similarterms';
+    $view->description = '';
+    $view->tag = 'default';
+    $view->base_table = 'node';
+    $view->human_name = 'test_similarterms';
+    $view->core = 7;
+    $view->api_version = '3.0';
+    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+
+    /* Display: Master */
+    $handler = $view->new_display('default', 'Master', 'default');
+    $handler->display->display_options['title'] = 'test';
+    $handler->display->display_options['access']['type'] = 'perm';
+    $handler->display->display_options['cache']['type'] = 'none';
+    $handler->display->display_options['query']['type'] = 'views_query';
+    $handler->display->display_options['query']['options']['distinct'] = TRUE;
+    $handler->display->display_options['exposed_form']['type'] = 'basic';
+    $handler->display->display_options['pager']['type'] = 'full';
+    $handler->display->display_options['pager']['options']['items_per_page'] = '10';
+    $handler->display->display_options['style_plugin'] = 'default';
+    $handler->display->display_options['row_plugin'] = 'fields';
+    /* Contextual filter: Similar By Terms: Nid */
+    $handler->display->display_options['arguments']['nid']['id'] = 'nid';
+    $handler->display->display_options['arguments']['nid']['table'] = 'similarterms';
+    $handler->display->display_options['arguments']['nid']['field'] = 'nid';
+    $handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
+    $handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
+    $handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
+    $handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
+    $handler->display->display_options['arguments']['nid']['vocabularies'] = array(
+      1 => 0,
+    );
+    $handler->display->display_options['arguments']['nid']['include_args'] = 0;
+    /* Sort criterion: Content: Nid */
+    $handler->display->display_options['sorts']['nid']['id'] = 'nid';
+    $handler->display->display_options['sorts']['nid']['table'] = 'node';
+    $handler->display->display_options['sorts']['nid']['field'] = 'nid';
+
+    return $view;
+  }
+
+  /**
+   * Helper function: verify a result set returned by view.
+   *
+   * The comparison is done on the string representation of the columns of the
+   * column map, taking the order of the rows into account, but not the order
+   * of the columns.
+   *
+   * @param $view
+   *  An executed View.
+   * @param $expected_result
+   *  An expected result set.
+   * @param $column_map
+   *  An associative array mapping the columns of the result set from the view
+   *  (as keys) and the expected result set (as values).
+   */
+  protected function assertIdenticalResultset($view, $expected_result, $column_map = array(), $message = 'Identical result set') {
+    return $this->assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, 'assertIdentical');
+  }
+
+  /**
+   * Helper function: verify a result set returned by view..
+   *
+   * Inverse of ViewsTestCase::assertIdenticalResultset().
+   *
+   * @param $view
+   *  An executed View.
+   * @param $expected_result
+   *  An expected result set.
+   * @param $column_map
+   *  An associative array mapping the columns of the result set from the view
+   *  (as keys) and the expected result set (as values).
+   */
+  protected function assertNotIdenticalResultset($view, $expected_result, $column_map = array(), $message = 'Identical result set') {
+    return $this->assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, 'assertNotIdentical');
+  }
+
+  protected function assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, $assert_method) {
+    // Convert $view->result to an array of arrays.
+    $result = array();
+    foreach ($view->result as $key => $value) {
+      $row = array();
+      foreach ($column_map as $view_column => $expected_column) {
+        // The comparison will be done on the string representation of the value.
+        $row[$expected_column] = (string) $value->$view_column;
+      }
+      $result[$key] = $row;
+    }
+
+    // Remove the columns we don't need from the expected result.
+    foreach ($expected_result as $key => $value) {
+      $row = array();
+      foreach ($column_map as $expected_column) {
+        // The comparison will be done on the string representation of the value.
+        $row[$expected_column] = (string) (is_object($value) ? $value->$expected_column : $value[$expected_column]);
+      }
+      $expected_result[$key] = $row;
+    }
+
+    // Reset the numbering of the arrays.
+    $result = array_values($result);
+    $expected_result = array_values($expected_result);
+
+    $this->verbose('<pre>Returned data set: ' . print_r($result, TRUE) . "\n\nExpected: ". print_r($expected_result, TRUE));
+
+    // Do the actual comparison.
+    return $this->$assert_method($result, $expected_result, $message);
+  }
+}
diff --git a/views/similarterms.views.inc b/views/similarterms.views.inc
old mode 100644
new mode 100755
index f1d294d..dcb72fb
--- a/views/similarterms.views.inc
+++ b/views/similarterms.views.inc
@@ -1,21 +1,13 @@
 <?php
 
 /**
- * @file Similar By Terms Views data include file
- */
-
-function similarterms_views_data() {
-  
-  // Basic table information.
-  $data['similarterms']['table']['group']  = t('Similar By Terms');
-
-  // what's this do?
-  $data['similarterms']['table']['join'] = array(
-    '#global' => array(),
-  );
-  
-  $data['similarterms']['similarterms'] = array(
+ * Implements hook_views_data()
+ **/
+function similarterms_views_data_alter(&$data) {
+  $data['similarterms']['similarterms']['moved to'] = array('node', 'similarterms');
+  $data['node']['similarterms'] = array(
     'title' => t('Similarity'),
+    'group' => t('Similar By Terms'),
     'help' => t('Percentage/count of terms which node has in common with node given as argument.'),
     'field' => array(
       'handler' => 'similarterms_handler_field_similar',
@@ -25,44 +17,17 @@ function similarterms_views_data() {
       'handler' => 'similarterms_handler_sort_similar',
     ),
   );
-  
-  // nid
-  $data['similarterms']['nid'] = array(
+  $data['similarterms']['nid']['moved to'] = array('node', 'similar_nid');
+  $data['node']['similar_nid'] = array(
     'title' => t('Nid'),
+    'group' => t('Similar By Terms'),
     'help' => t('ID of content item(s). Passes term ids to Similar By Terms.'), // The help that appears on the UI,
-    
-    // Information for accepting a nid as an argument
     'argument' => array(
       'handler' => 'similarterms_handler_argument_node_nid',
-      'parent' => 'views_handler_argument_numeric', // make sure parent is included
+      // 'parent' => 'views_handler_argument_numeric', // make sure parent is included
       'name field' => 'title', // the field to display in the summary.
       'numeric' => TRUE,
       'validate type' => 'nid',
     ),
-
-  );
-
-  return $data;
-}
-
-/**
- * Implementation of hook_views_handlers().
- */
-function similarterms_views_handlers() {
-  return array(
-    'info' => array(
-      'path' => drupal_get_path('module', 'similarterms') . '/views',
-    ),
-    'handlers' => array(
-      'similarterms_handler_sort_similar' => array(
-        'parent' => 'views_handler_sort',
-      ),
-      'similarterms_handler_argument_node_nid' => array(
-        'parent' => 'views_handler_argument_numeric',
-      ),
-      'similarterms_handler_field_similar' => array(
-        'parent' => 'views_handler_field',
-      ),
-    ),
   );
 }
diff --git a/views/similarterms.views_default.inc b/views/similarterms.views_default.inc
old mode 100644
new mode 100755
index 0db8476..5be39ca
--- a/views/similarterms.views_default.inc
+++ b/views/similarterms.views_default.inc
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * Implementation of hook_views_default_views().
+ * Implements hook_views_default_views().
  */
 function similarterms_views_default_views() {
   /*
@@ -10,172 +10,68 @@ function similarterms_views_default_views() {
   $view = new view;
   $view->name = 'similarterms';
   $view->description = 'Similar By Terms';
-  $view->tag = 'similarterms';
-  $view->view_php = '';
+  $view->tag = 'default';
   $view->base_table = 'node';
-  $view->is_cacheable = FALSE;
-  $view->api_version = 2;
+  $view->human_name = 'Similar By Terms';
+  $view->core = 7;
+  $view->api_version = '3.0';
   $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
-  $handler = $view->new_display('default', 'Defaults', 'default');
-  $handler->override_option('fields', array(
-    'title' => array(
-      'label' => '',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'link_to_node' => 1,
-      'exclude' => 0,
-      'id' => 'title',
-      'table' => 'node',
-      'field' => 'title',
-      'relationship' => 'none',
-      'override' => array(
-        'button' => 'Override',
-      ),
-    ),
-  ));
-  $handler->override_option('sorts', array(
-    'similarterms' => array(
-      'order' => 'DESC',
-      'id' => 'similarterms',
-      'table' => 'similarterms',
-      'field' => 'similarterms',
-      'relationship' => 'none',
-      'override' => array(
-        'button' => 'Override',
-      ),
-    ),
-  ));
-  $handler->override_option('arguments', array(
-    'nid' => array(
-      'default_action' => 'default',
-      'style_plugin' => 'default_summary',
-      'style_options' => array(),
-      'wildcard' => 'all',
-      'wildcard_substitution' => 'All',
-      'title' => '',
-      'breadcrumb' => '',
-      'default_argument_type' => 'node',
-      'default_argument' => '',
-      'validate_type' => 'node',
-      'validate_fail' => 'not found',
-      'break_phrase' => 0,
-      'not' => 0,
-      'id' => 'nid',
-      'table' => 'similarterms',
-      'field' => 'nid',
-      'validate_user_argument_type' => 'uid',
-      'validate_user_roles' => array(
-        '2' => 0,
-        '4' => 0,
-        '3' => 0,
-      ),
-      'override' => array(
-        'button' => 'Override',
-      ),
-      'relationship' => 'none',
-      'default_options_div_prefix' => '',
-      'default_argument_fixed' => '',
-      'default_argument_user' => 0,
-      'default_argument_php' => '',
-      'validate_argument_node_type' => array(
-        'blog' => 0,
-        'product' => 0,
-        'presenter' => 0,
-        'playlist_video' => 0,
-        'standalone_video' => 0,
-        'page' => 0,
-      ),
-      'validate_argument_node_access' => 0,
-      'validate_argument_nid_type' => 'nid',
-      'validate_argument_vocabulary' => array(
-        '1' => 0,
-        '3' => 0,
-        '2' => 0,
-        '4' => 0,
-      ),
-      'validate_argument_type' => 'tid',
-      'validate_argument_transform' => 0,
-      'validate_user_restrict_roles' => 0,
-      'validate_argument_node_flag_name' => '*relationship*',
-      'validate_argument_node_flag_test' => 'flaggable',
-      'validate_argument_node_flag_id_type' => 'id',
-      'validate_argument_user_flag_name' => '*relationship*',
-      'validate_argument_user_flag_test' => 'flaggable',
-      'validate_argument_user_flag_id_type' => 'id',
-      'validate_argument_php' => '',
-    ),
-  ));
-  $handler->override_option('filters', array(
-    'moderate' => array(
-      'operator' => '=',
-      'value' => '0',
-      'group' => '0',
-      'exposed' => FALSE,
-      'expose' => array(
-        'operator' => FALSE,
-        'label' => '',
-      ),
-      'id' => 'moderate',
-      'table' => 'node',
-      'field' => 'moderate',
-      'override' => array(
-        'button' => 'Override',
-      ),
-      'relationship' => 'none',
-    ),
-    'status' => array(
-      'operator' => '=',
-      'value' => '1',
-      'group' => '0',
-      'exposed' => FALSE,
-      'expose' => array(
-        'operator' => FALSE,
-        'label' => '',
-      ),
-      'id' => 'status',
-      'table' => 'node',
-      'field' => 'status',
-      'override' => array(
-        'button' => 'Override',
-      ),
-      'relationship' => 'none',
-    ),
-  ));
-  $handler->override_option('access', array(
-    'type' => 'none',
-  ));
-  $handler->override_option('cache', array(
-    'type' => 'none',
-  ));
-  $handler->override_option('title', 'Similar By Terms');
-  $handler->override_option('items_per_page', 7);
-  $handler = $view->new_display('block', 'Block', 'block_1');
-  $handler->override_option('block_description', '');
-  $handler->override_option('block_caching', '4');
+
+  /* Display: Master */
+  $handler = $view->new_display('default', 'Master', 'default');
+  $handler->display->display_options['title'] = 'Related Terms';
+  $handler->display->display_options['access']['type'] = 'perm';
+  $handler->display->display_options['cache']['type'] = 'none';
+  $handler->display->display_options['query']['type'] = 'views_query';
+  $handler->display->display_options['query']['options']['query_comment'] = FALSE;
+  $handler->display->display_options['exposed_form']['type'] = 'basic';
+  $handler->display->display_options['pager']['type'] = 'some';
+  $handler->display->display_options['pager']['options']['items_per_page'] = '5';
+  $handler->display->display_options['style_plugin'] = 'default';
+  $handler->display->display_options['row_plugin'] = 'fields';
+  /* Field: Content: Title */
+  $handler->display->display_options['fields']['title']['id'] = 'title';
+  $handler->display->display_options['fields']['title']['table'] = 'node';
+  $handler->display->display_options['fields']['title']['field'] = 'title';
+  $handler->display->display_options['fields']['title']['label'] = '';
+  $handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
+  $handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
+  $handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
+  $handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
+  $handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
+  $handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
+  $handler->display->display_options['fields']['title']['alter']['trim'] = 0;
+  $handler->display->display_options['fields']['title']['alter']['html'] = 0;
+  $handler->display->display_options['fields']['title']['hide_empty'] = 0;
+  $handler->display->display_options['fields']['title']['empty_zero'] = 0;
+  $handler->display->display_options['fields']['title']['link_to_node'] = 1;
+  /* Sort criterion: Similar By Terms: Similarity */
+  $handler->display->display_options['sorts']['similarterms']['id'] = 'similarterms';
+  $handler->display->display_options['sorts']['similarterms']['table'] = 'node';
+  $handler->display->display_options['sorts']['similarterms']['field'] = 'similarterms';
+  /* Contextual filter: Similar By Terms: Nid */
+  $handler->display->display_options['arguments']['similar_nid']['id'] = 'similar_nid';
+  $handler->display->display_options['arguments']['similar_nid']['table'] = 'node';
+  $handler->display->display_options['arguments']['similar_nid']['field'] = 'similar_nid';
+  $handler->display->display_options['arguments']['similar_nid']['default_action'] = 'default';
+  $handler->display->display_options['arguments']['similar_nid']['default_argument_type'] = 'node';
+  $handler->display->display_options['arguments']['similar_nid']['default_argument_skip_url'] = 0;
+  $handler->display->display_options['arguments']['similar_nid']['summary']['number_of_records'] = '0';
+  $handler->display->display_options['arguments']['similar_nid']['summary']['format'] = 'default_summary';
+  $handler->display->display_options['arguments']['similar_nid']['summary_options']['items_per_page'] = '25';
+  $handler->display->display_options['arguments']['similar_nid']['break_phrase'] = 0;
+  /* Filter criterion: Content: Published */
+  $handler->display->display_options['filters']['status']['id'] = 'status';
+  $handler->display->display_options['filters']['status']['table'] = 'node';
+  $handler->display->display_options['filters']['status']['field'] = 'status';
+  $handler->display->display_options['filters']['status']['value'] = 1;
+  $handler->display->display_options['filters']['status']['group'] = 1;
+  $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
+
+  /* Display: Block */
+  $handler = $view->new_display('block', 'Block', 'block');
+  $handler->display->display_options['block_caching'] = '4';
   $views[$view->name] = $view;
 
   return $views;
 }
-
-
-
-
diff --git a/views/similarterms_handler_argument_node_nid.inc b/views/similarterms_handler_argument_node_nid.inc
old mode 100644
new mode 100755
index 76971a3..2c1da8f
--- a/views/similarterms_handler_argument_node_nid.inc
+++ b/views/similarterms_handler_argument_node_nid.inc
@@ -1,14 +1,10 @@
 <?php
-// $Id $
-/**
- * @file
- * Provide node nid argument handler.
- */
-
 /**
  * Argument handler to accept a node id.
  * based on node_handler_argument_node_nid except that it doesn't
- * add a where clause to the query
+ * add a where clause to the query.
+ *
+ * @ingroup views_argument_handlers
  */
 class similarterms_handler_argument_node_nid extends views_handler_argument_numeric {
   /**
@@ -16,43 +12,54 @@ class similarterms_handler_argument_node_nid extends views_handler_argument_nume
    */
   function title_query() {
     $titles = array();
-    $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
 
-    $result = db_query("SELECT n.title FROM {node} n WHERE n.nid IN ($placeholders)", $this->value);
-    while ($term = db_fetch_object($result)) {
+    $select = db_select('node', 'n');
+    $select->addField('n', 'title');
+    $select->condition('n.nid', $this->value, 'IN');
+    $select->addTag('node_access');
+    $result = $select->execute();
+
+    foreach ($result as $term) {
       $titles[] = check_plain($term->title);
     }
+
     return $titles;
   }
-  
+
   function option_definition() {
     $options = parent::option_definition();
 
     $options['vocabularies'] = array('default' => array());
     $options['include_args'] = array('default' => FALSE);
-    
+
     return $options;
   }
-  
+
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
-    
+
     unset($form['not']);
-    
-    $r = db_query('SELECT vid, name FROM {vocabulary} ORDER BY weight');
-    while ($row = db_fetch_object($r)) {
-      $vocabs[$row->vid] = $row->name;
+
+    $vocabularies = array();
+    $result = db_query('SELECT vid, name FROM {taxonomy_vocabulary} ORDER BY weight');
+    foreach ($result as $vocabulary) {
+      $vocabularies[$vocabulary->vid] = $vocabulary->name;
     }
-    
-    $form['vocabularies'] = array(
+
+    $form['similarterms'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Similarity by Terms'),
+      '#collapsible' => FALSE,
+    );
+    $form['similarterms']['vocabularies'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Limit similarity to terms within these vocabularies'),
       '#description' => t('Choosing any vocabularies here will limit the terms used to calculate similarity. It is usually best NOT to limit the terms, but in some cases this is necessary. Leave all checkboxes unselected to not limit terms.'),
-      '#options' => $vocabs,
+      '#options' => $vocabularies,
       '#default_value' => empty($this->options['vocabularies']) ? array() : $this->options['vocabularies'],
     );
-    
-    $form['include_args'] = array(
+
+    $form['similarterms']['include_args'] = array(
       '#type' => 'checkbox',
       '#title' => t('Include argument node(s) in results'),
       '#description' => t('If selected, the node(s) passed as the argument will be included in the view results.'),
@@ -60,108 +67,65 @@ class similarterms_handler_argument_node_nid extends views_handler_argument_nume
     );
 
   }
-  
+
   function validate_arg($arg) {
-    
     // first run the inherited arg validation
     if (!parent::validate_arg($arg)) {
       return FALSE;
     }
-  
+
     // hmmm... @todo: wildcard validation?
     // see views_handler_argument.inc for possible code
-  
+
     if (!empty($this->options['break_phrase'])) {
       views_break_phrase($this->argument, $this);
     }
     else {
       $this->value = array($this->argument);
     }
-        
-    // $vids is array node version ids
-    $vids = array();
-    foreach($this->value as $nid) {
-      // get the current revision id (vid) for this node id (nid)
-      $vids[] = db_result(db_query("SELECT vid FROM {node} WHERE nid = %d", $nid));
-    }
-        
-    // $vocabs is array of vocabulary ids (a.k.a. vids, confusing right?)
-    $vocabs = empty($this->options['vocabularies']) ? array() : $this->options['vocabularies'];
-    foreach ($vocabs as $key => $val) {
+
+    // $vocabulary_vids is array of vocabulary ids (a.k.a. vids, confusing right?)
+    $vocabulary_vids = empty($this->options['vocabularies']) ? array() : $this->options['vocabularies'];
+    foreach ($vocabulary_vids as $key => $val) {
       if ($val == 0) {
-        unset($vocabs[$key]);
+        unset($vocabulary_vids[$key]);
       }
     }
-        
-    $addwhere = '';
-    $addjoin = '';
-    if (count($vocabs) == 1) {
-      // we're limiting the terms to those of given vocabs
-      $addjoin = ' INNER JOIN {term_data} td ON tn.tid = td.tid ';
-      $addwhere = " AND td.vid = %d";
-    }
-    elseif (count($vocabs) > 1) {
-      $addjoin = ' INNER JOIN {term_data} td ON tn.tid = td.tid ';
-      $placeholders = implode(', ', array_fill(0, sizeof($vocabs), '%d'));
-      $addwhere = " AND td.vid IN ($placeholders)";
-    }
-    
-    $args = array_merge($vids, $vocabs);
-    if (count($vids) > 1) {
-      $placeholders = implode(', ', array_fill(0, sizeof($vids), '%d'));
-      $result = db_query("SELECT tn.tid FROM {term_node} tn $addjoin WHERE tn.vid IN ($placeholders) $addwhere", $args);
-    }
-    else {
-      $result = db_query("SELECT tn.tid FROM {term_node} tn $addjoin WHERE tn.vid = %d $addwhere", $args);
+
+    $select = db_select('taxonomy_index', 'ti');
+    $select->addField('ti', 'tid');
+
+    if (count($vocabulary_vids)) {
+      $select->join('taxonomy_term_data', 'td', 'ti.tid = td.tid');
+      $select->condition('td.vid', $vocabulary_vids, 'IN');
     }
-    
-    $tids = array();
-    while ($row = db_fetch_object($result)) {
-      // adding a key to ensure there aren't duplicates
-      $tids[$row->tid] = $row->tid;
+    $select->condition('ti.nid', $this->value, 'IN');
+    $result = $select->execute();
+
+    $this->tids = array();
+    foreach ($result as $row) {
+      $this->tids[$row->tid] = $row->tid;
     }
-    
-    $this->tids = $tids;
-    $this->view->tids = $tids;
-    
-    if (count($tids) == 0) {
-      // there are no terms...
-      // we need to cancel the query and bail out
+    $this->view->tids = $this->tids;
+
+    if (count($this->tids) == 0) {
+      // there are no terms ... we need to cancel the query and bail out
       return FALSE;
     }
-    
+
     return TRUE;
-    
   }
-  
-  
-  function query() {
-  
+
+  function query($group_by = FALSE) {
     $this->ensure_my_table();
-        
-    $tids = $this->tids;
-  
-    $v = $this->query->add_table('term_node');
-              
-    if (count($tids) == 1) {
-      $this->query->add_where(0, "term_node.tid = %d", $tids);
-    }
-    elseif (count($tids) > 1) {
-      $placeholders = implode(', ', array_fill(0, count($tids), '%d'));
-      $this->query->add_where(0, "term_node.tid IN ($placeholders)", $tids);
-    }
-          
+
+    $this->query->add_table('taxonomy_index', NULL, NULL, 'similarterms_taxonomy_index');
+    $this->query->add_where(0, "similarterms_taxonomy_index.tid", $this->tids, 'IN');
+
     // exclude the current node(s)
     if (empty($this->options['include_args'])) {
-      if (count($this->value) > 1) {
-        $placeholders = implode(', ', array_fill(0, count($this->value), '%d'));
-        $this->query->add_where(0, "node.nid NOT IN ($placeholders)", $this->value);
-      }
-      else {
-        $this->query->add_where(0, 'node.nid != %d', $this->value[0]);
-      }
+      $this->query->add_where(0, "node.nid", $this->value, 'NOT IN');
     }
-    
   }
-  
-}
\ No newline at end of file
+
+}
diff --git a/views/similarterms_handler_field_similar.inc b/views/similarterms_handler_field_similar.inc
old mode 100644
new mode 100755
index a5a15d9..bfc5d4e
--- a/views/similarterms_handler_field_similar.inc
+++ b/views/similarterms_handler_field_similar.inc
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ * Shows the similarity of the node.
+ *
+ * @ingroup views_field_handlers
+ */
 class similarterms_handler_field_similar extends views_handler_field {
   function option_definition() {
     $options = parent::option_definition();
@@ -20,30 +25,33 @@ class similarterms_handler_field_similar extends views_handler_field {
         1 => t('Show as percentage'),
       ),
     );
-    
+
     $form['percent_suffix'] = array(
       '#type' => 'checkbox',
       '#title' => t('Append % when showing percentage'),
       '#default_value' => !empty($this->options['percent_suffix']),
     );
-        
   }
 
   function query() {
     // we MIGHT want to ensure that the COUNT data is getting added here.
+    $params = array(
+      'function' => 'count',
+    );
+    $this->field_alias = $this->query->add_field('node', 'nid', NULL, $params);
   }
 
   function render($values) {
     if ($this->options['count_type'] == 0) {
-      return $values->node_count;
+      return $values->{$this->field_alias};
     }
     elseif ($this->view->tids) {
-      $output = round($values->node_count/count($this->view->tids) * 100);
+      $output = round($values->{$this->field_alias}/count($this->view->tids) * 100);
       if (!empty($this->options['percent_suffix'])) {
         $output .= '%';
       }
       return $output;
     }
-    
+
   }
-}
\ No newline at end of file
+}
diff --git a/views/similarterms_handler_sort_similar.inc b/views/similarterms_handler_sort_similar.inc
old mode 100644
new mode 100755
index 071f99e..a060897
--- a/views/similarterms_handler_sort_similar.inc
+++ b/views/similarterms_handler_sort_similar.inc
@@ -1,26 +1,20 @@
 <?php
-
+/**
+ * Handler which sorts the by the similarity.
+ *
+ * @ingroups views_sort_handlers
+ */
 class similarterms_handler_sort_similar extends views_handler_sort {
-  
+
   function option_definition() {
     $options = parent::option_definition();
-
     $options['order'] = array('default' => 'DESC');
-
     return $options;
   }
 
   function query() {
-      
-    // add function to count nid occurrences based on grouping 
-    $this->query->add_field(NULL, 'COUNT(node.nid)', 'node_count', array('aggregate' => TRUE));
-        
-    // sort 'em
-    $this->query->add_orderby(NULL, NULL, $this->options['order'], 'node_count');
-    
-    // group 'em
-    $this->query->add_groupby('nid');
-        
+    $this->ensure_my_table();
+    $this->query->add_orderby($this->table_alias, 'nid', $this->options['order'], NULL, array('function' => 'count'));
   }
 
 }
