diff --git a/taxonomy_nco.module b/taxonomy_nco.module
index b35b82e..26d76a9 100755
--- a/taxonomy_nco.module
+++ b/taxonomy_nco.module
@@ -25,7 +25,7 @@
 
 DEFINE('MINIMUM_MATCH_INTERSECTION', 3); // we must have intersection >= to this to find matches
 DEFINE('DEFAULT_MINIMUM_MATCH_NCO', 0.032); // We must have NCO >= to this to find a match - this is the default if you don't pass a value
-DEFINE('DEFAULT_INCLUDE_NODE_TAGS','auto'); // Whether to include node tags in the related terms block, when displayed in node context
+DEFINE('DEFAULT_INCLUDE_NODE_TAGS', 'auto'); // Whether to include node tags in the related terms block, when displayed in node context
 
 /*
  * Implementation of hook_theme
@@ -80,7 +80,7 @@ function taxonomy_nco_menu() {
  * @return array the form definition
  */
 function taxonomy_nco_admin_form($form_state) {
-  $include_tags_in_related = variable_get('taxonomy_nco_include_tags_in_related','auto');
+  $include_tags_in_related = variable_get('taxonomy_nco_include_tags_in_related', 'auto');
   $form['include_tags_in_related'] = array(
     '#type' => 'select',
     '#title' => t('Include Node Tags in Related Terms'),
@@ -115,7 +115,7 @@ function taxonomy_nco_admin_form_validate($form, &$form_state) {
  */
 function taxonomy_nco_admin_form_submit($form, &$form_state) {
   $include_tags_in_related = $form_state['values']['include_tags_in_related'];
-  variable_set('taxonomy_nco_include_tags_in_related',$include_tags_in_related);
+  variable_set('taxonomy_nco_include_tags_in_related', $include_tags_in_related);
 }
 
 
@@ -133,7 +133,7 @@ function taxonomy_nco_admin_form_submit($form, &$form_state) {
  */
 function taxonomy_nco_related_terms($tids, $minimum_match_nco = -1) {
   // TODO: check this string is a float
-  //watchdog('taxonomy nco', 'Similar terms request NCO: '. $minimum_match_nco .' tids: '. print_r($tids, 1));
+  //watchdog('taxonomy nco', 'Similar terms request NCO: ' . $minimum_match_nco . ' tids: ' . print_r($tids, 1));
   if ($minimum_match_nco == '' or $minimum_match_nco == -1) {
     $minimum_match_nco = variable_get('taxonomy_nco_default_minimum_match_nco', DEFAULT_MINIMUM_MATCH_NCO);
   }
@@ -141,26 +141,26 @@ function taxonomy_nco_related_terms($tids, $minimum_match_nco = -1) {
   // todo: check this caching is working in D7
   // todo?: cache all results rather than just the latest result?
   static $similars = array();
-  sort($tids,SORT_NUMERIC); //ensures caching will work even if same tids are presented in different order
+  sort($tids, SORT_NUMERIC); //ensures caching will work even if same tids are presented in different order
   $output = NULL;
   // check to see if we can just serve up the cache ..
   if (array_key_exists('input_tids', $similars) && array_key_exists('minimum_nco', $similars)) {
     if (($similars['input_tids'] == $tids) && ($similars['minimum_nco'] == $minimum_match_nco)) {
-      if (array_key_exists('output_tids')) {	
-    	$output = $similars['output_tids'];
+      if (array_key_exists('output_tids')) {  
+      $output = $similars['output_tids'];
       }
     }
   }
   else {  //otherswise we'd better to the sums ..
-    //watchdog('taxonomy nco', 'tid_list: '. implode($tids,',') .' minimum nco: '. $minimum_match_nco);
+    //watchdog('taxonomy nco', 'tid_list: ' . implode($tids, ',') . ' minimum nco: ' . $minimum_match_nco);
     // get automatic nco related terms
     $minimum_match_intersection = variable_get('taxonomy_nco_minimum_match_intersection', MINIMUM_MATCH_INTERSECTION);
 
-    $sel = db_select('taxonomy_nco','t')
-      ->fields('t',array('tid_b'))
-      ->condition('tid_a',$tids,'IN')
-      ->condition('a_and_b',$minimum_match_intersection,'>=')
-      ->condition('nco',$minimum_match_nco,'>=')
+    $sel = db_select('taxonomy_nco', 't')
+      ->fields('t', array('tid_b'))
+      ->condition('tid_a', $tids, 'IN')
+      ->condition('a_and_b', $minimum_match_intersection, '>=')
+      ->condition('nco', $minimum_match_nco, '>=')
       ->groupBy('tid_b');
 
     //where there are multiple tids passed, there may be multiple nco results for each related tid
@@ -168,16 +168,16 @@ function taxonomy_nco_related_terms($tids, $minimum_match_nco = -1) {
     $ncoAlias = $sel->addExpression('max(nco)');
 
     $rows = $sel->execute();
-    foreach($rows as $row){
+    foreach ($rows as $row) {
       $output[$row->tid_b] = $row->$ncoAlias;
     }
 
     // now get manual overrides
-    $rows = db_select('taxonomy_nco_forced','t')
-      ->fields('t',array('tid_b','nco'))
-      ->condition('tid_a',$tids,'IN')
+    $rows = db_select('taxonomy_nco_forced', 't')
+      ->fields('t', array('tid_b', 'nco'))
+      ->condition('tid_a', $tids, 'IN')
       ->execute();    
-    foreach($rows as $row) {
+    foreach ($rows as $row) {
       $output[$row->tid_b] = $row->nco;
     }
     if (is_array($output)) {
@@ -187,7 +187,7 @@ function taxonomy_nco_related_terms($tids, $minimum_match_nco = -1) {
     $similars['minimum_nco'] = $minimum_match_nco;
     $similars['output_tids'] = $output;
   }  
-  //watchdog('taxonomy nco', 'debug - output: '. print_r($output, 1));
+  //watchdog('taxonomy nco', 'debug - output: ' . print_r($output, 1));
   return $output;
 }
 
@@ -242,15 +242,15 @@ function taxonomy_nco_block_view($delta) {
 /**
  * Fish out all the tids used in the vocabulary used by nco
  */
-function taxonomy_nco_all_tids(){
-  static $result=null;
-  if ($result===null){
+function taxonomy_nco_all_tids() {
+  static $result=NULL;
+  if ($result===NULL) {
     $result=array();
-    $rows = db_select('taxonomy_nco','t')
-      ->fields('t',array('tid_a'))
+    $rows = db_select('taxonomy_nco', 't')
+      ->fields('t', array('tid_a'))
       ->distinct()
       ->execute();
-    while($row = $rows->fetchAssoc()) $result[]=$row['tid_a'];
+    while ($row = $rows->fetchAssoc()) $result[]=$row['tid_a'];
   }
   return $result;
 }
@@ -259,21 +259,23 @@ function taxonomy_nco_all_tids(){
  * Fish out the tids assigned to the node from the vocabulary used by nco
  */
 
-function taxonomy_nco_tids_from_node($nid){
+function taxonomy_nco_tids_from_node($nid) {
   static $results=array();
-  if (array_key_exists($nid,$results)) return $results[$nid];
+  if (array_key_exists($nid, $results)) return $results[$nid];
   $result=array();
-  if (is_numeric($nid)){
+  if (is_numeric($nid)) {
     $node=node_load($nid);
-    if ($node){
-      foreach($node as $key=>$field_value){
-        if (strpos($key,'field_')===0){
-          if ($field_value){
+    if ($node) {
+      foreach ($node as $key => $field_value) {
+        if (strpos($key, 'field_')===0) {
+          if ($field_value) {
             $field_name = $key;
             $field = field_info_field($field_name);
-            if ($field['type']=='taxonomy_term_reference'){
-              $tags = $field_value[$node->language];
-              foreach($tags as $tag) $result[] = $tag['tid'];            
+            if ($field['type']=='taxonomy_term_reference') {
+              if (array_key_exists($node->language, $field_value)) $tags = $field_value[$node->language];
+              elseif (array_key_exists('und', $field_value)) $tags = $field_value['und'];
+              else $tags = array_shift($field_value);
+              if ($tags) foreach ($tags as $tag) $result[] = $tag['tid'];            
             }
           }
         }
@@ -294,7 +296,7 @@ function taxonomy_nco_tids_from_node($nid){
 function taxonomy_nco_relationship_block_contents() {
   $output = '';
   $tids = array();
-  switch(arg(0)){
+  switch (arg(0)) {
     case 'taxonomy':
       $tid = arg(2);
       $tids[] = $tid;
@@ -305,21 +307,21 @@ function taxonomy_nco_relationship_block_contents() {
       break;
     default: break; 
   }
-  if ($tids){
+  if ($tids) {
     // only show the block if it is relevant, ie if the node/taxonomy term has some tids
     // from our target vocabulary
     // we only want to know about tids in our own vocabulary
     // since, strictly speaking, we do not know in THIS module (only the analysis module)
     // which vocabulary we are using, we'll read back the tids we use for nco, and only use the ones
     // found in our nco table
-    $tids = array_intersect($tids,taxonomy_nco_all_tids());
+    $tids = array_intersect($tids, taxonomy_nco_all_tids());
 
-    if ($tids){
-      $variables = array('tids' => $tids, 'minimum_nco' => NULL,  'display_counts' => FALSE, 'context'=>arg(0));
+    if ($tids) {
+      $variables = array('tids' => $tids, 'minimum_nco' => NULL,  'display_counts' => FALSE, 'context' => arg(0));
       $related_terms_output = theme('taxonomy_nco_related_terms', $variables);
-      $output .= t('Related subjects').': '. $related_terms_output;
+      $output .= t('Related subjects') . ': ' . $related_terms_output;
       $output .= '<br />';
-      //$output .= ' tid: '.$tid;
+      //$output .= ' tid: ' . $tid;
       $output .= '<br />';
     }
   }
@@ -367,24 +369,24 @@ function theme_taxonomy_nco_related_terms($variables) {
   
   $related_terms = taxonomy_nco_similar_terms($tids, $minimum_nco);
   // debug:
-  watchdog('taxonomy nco', 'related terms: '. $related_terms);
+  watchdog('taxonomy nco', 'related terms: ' . $related_terms);
 
   // include/exclude node tags based on user-specified preference
-  if ($variables['context']=='node'){
-    if ($related_terms){
-      $include_tags_in_related = variable_get('taxonomy_nco_include_tags_in_related','auto');
-      switch($include_tags_in_related){
+  if ($variables['context']=='node') {
+    if ($related_terms) {
+      $include_tags_in_related = variable_get('taxonomy_nco_include_tags_in_related', 'auto');
+      switch ($include_tags_in_related) {
         case 'auto': break; //no further action to take
         case 'include':
           //remove node's own tags if they are already present, 
           //insert node's own tags at top of the list
-          $related_terms = array_diff($related_terms,$tids);
-          foreach($tids as $tid){
-            array_unshift($related_terms,$tid);
+          $related_terms = array_diff($related_terms, $tids);
+          foreach ($tids as $tid) {
+            array_unshift($related_terms, $tid);
           }
           break;
         case 'exclude':
-          $related_terms = array_diff($related_terms,$tids);
+          $related_terms = array_diff($related_terms, $tids);
           break;
         default: break; //should never happen.... throw exception? 
       }
@@ -557,7 +559,7 @@ function taxonomy_nco_get_tid_node_count($tid, $type = '- ALL -') {
 function theme_taxonomy_nco_term_link($variables) {
   $tid = $variables['0'];
   $display_counts = $variables['1'];
-  //watchdog('taxonomy nco', 'theme term link tid: '. print_r($tid, 1));
+  //watchdog('taxonomy nco', 'theme term link tid: ' . print_r($tid, 1));
   if (is_numeric($tid)) {
     $term = taxonomy_term_load($tid);
     $title_array = NULL;
@@ -570,7 +572,7 @@ function theme_taxonomy_nco_term_link($variables) {
       );
       $title_array = array('title' => $title);
     }
-    //watchdog('taxonomy nco', 'theme term link term: '. print_r($term, 1));
+    //watchdog('taxonomy nco', 'theme term link term: ' . print_r($term, 1));
     $term_uri_output = taxonomy_term_uri($term);
     $term_path = $term_uri_output['path'];
     $output = l($term->name, $term_path, array('attributes' => array($title_array)));
@@ -615,7 +617,7 @@ function taxonomy_nco_views_arguments() {
 function views_handler_arg_taxonomy_nco($op, &$query, $argtype, $arg = '') {
   switch ($op) {
     case 'summary':
-      $query->ensure_table('taxonomy_term_data', true);
+      $query->ensure_table('taxonomy_term_data', TRUE);
       $query->add_field('name', 'taxonomy_term_data');
       $query->add_field('weight', 'taxonomy_term_data');
       $query->add_field('tid', 'taxonomy_term_data');
diff --git a/taxonomy_nco_analysis.module b/taxonomy_nco_analysis.module
index 0450a02..374007b 100755
--- a/taxonomy_nco_analysis.module
+++ b/taxonomy_nco_analysis.module
@@ -149,7 +149,7 @@ function taxonomy_nco_analysis_block($op = 'list', $delta = 0, $edit = array())
     );
     return $blocks;
   }
-  else if ($op == 'view') {
+  elseif ($op == 'view') {
     switch ($delta) {
       case 'nco_force':
         $block['subject'] = 'Term relationships';
@@ -308,7 +308,7 @@ function taxonomy_nco_analysis_start_confirm($foo) {
  */
 function taxonomy_nco_analysis_start_confirm_submit($form, &$form_state) {
   taxonomy_nco_analysis_initiate_global_analysis(0);
-  drupal_set_message('Taxonomy NCO initial processing run initiated.');
+  drupal_set_message(t('Taxonomy NCO initial processing run initiated.'));
   drupal_goto('admin/config/taxonomy_nco_analysis');
 }
 
@@ -456,7 +456,7 @@ function taxonomy_nco_analysis_get_related_seeds($tid_b) {
   $result = db_query($sql, array(':tid_b' => $tid_b));
   $tids = NULL;
   foreach ($result as $record) {
-  	$tids[] = $record->tid_a;
+    $tids[] = $record->tid_a;
   }
   /*
   while ($row = db_fetch_array($result)) {
@@ -468,7 +468,7 @@ function taxonomy_nco_analysis_get_related_seeds($tid_b) {
 
 
 /**
- * return true if this term is a seed term
+ * return TRUE if this term is a seed term
  *
  * @param unknown_type $tid
  */
@@ -476,8 +476,8 @@ function taxonomy_nco_analysis_is_seed($tid) {
   $seed_term_ocurrence_threshold = variable_get('taxonomy_nco_analysis_seed_term_occurrence_threshold', SEED_TERM_OCCURENCE_THRESHOLD);
   $sql = "select count(tid) AS count from {taxonomy_index} where tid = :tid";
   $result = db_query($sql, array(':tid' => $tid));
-  foreach($result as $record) {
-  	$occurrence = $record->count;
+  foreach ($result as $record) {
+    $occurrence = $record->count;
   }
   //watchdog('debug', 'occurrence: '. $occurrence);  
   return $occurrence > $seed_term_ocurrence_threshold;
@@ -502,7 +502,7 @@ function taxonomy_nco_analysis_tids_on_nodes_updated_between($time, $now) {
   $result = db_query($sql, $placeholders);
   $tids = NULL;
   foreach ($result as $record) {
-  	$tids[] = $record->tid;
+    $tids[] = $record->tid;
   }
   return $tids;
 }
@@ -529,17 +529,17 @@ function taxonomy_nco_analysis_get_seed_terms($limit = 1000) {
   // limit for testing
   if ($limit > 0) {
     $placeholders = array(':vocabulary' => $vocabulary, 
-    				      ':seed_term_ocurrence_threshold' => $seed_term_ocurrence_threshold);
+                  ':seed_term_ocurrence_threshold' => $seed_term_ocurrence_threshold);
     $result_common_tids = db_query_range($sql_common_tids, 0, $limit, $placeholders);
   }
   else {
     $placeholders = array(':vocabulary' => $vocabulary, 
-    				      ':seed_term_ocurrence_threshold' => $seed_term_ocurrence_threshold);    
+                  ':seed_term_ocurrence_threshold' => $seed_term_ocurrence_threshold);    
     $result_common_tids = db_query($sql_common_tids, $placeholders);
   }
   $seed_terms = array();
-  foreach($result_common_tids as $record) {
-  	$seed_terms[] = $record->tid;
+  foreach ($result_common_tids as $record) {
+    $seed_terms[] = $record->tid;
   }
   return ($seed_terms);
 }
@@ -575,15 +575,15 @@ function taxonomy_nco_analysis_analyse_term($tid_a) {
   $placeholders = array(':tid_a' => $tid_a, ':vocabulary' => $vocabulary);
   $result_related_tids = db_query($sql_related_tids, $placeholders);
   // cycle through related terms analysing the relationships with this seed
-  foreach($result_related_tids as $record) {
+  foreach ($result_related_tids as $record) {
     if (taxonomy_nco_analysis_abort_check()) {
       return;
     }  
-    $tid_b = $record->tid;	
+    $tid_b = $record->tid;  
     if ($tid_a == $tid_b) {
       continue;
     }
-    taxonomy_nco_analysis_analyse_relationship($tid_a, $tid_b);  	
+    taxonomy_nco_analysis_analyse_relationship($tid_a, $tid_b);   
   }
 }
 
@@ -605,8 +605,8 @@ function taxonomy_nco_analysis_analyse_relationship($tid_a, $tid_b) {
   $placeholders = array(':tid_a' => $tid_a, ':tid_b' => $tid_b);
   $result_intersection = db_query($sql_intersection, $placeholders);
   
-  foreach($result_intersection as $record) {
-  	$intersection_count = $record->intersection_count;
+  foreach ($result_intersection as $record) {
+    $intersection_count = $record->intersection_count;
   }
   $mininum_analysis_intersection = variable_get('taxonomy_nco_analysis_minimum_analysis_intersection', MINIMUM_ANALYSIS_INTERSECTION);
   if ($intersection_count >= $mininum_analysis_intersection) {
@@ -614,8 +614,8 @@ function taxonomy_nco_analysis_analyse_relationship($tid_a, $tid_b) {
     $sql_union = "select count(DISTINCT ti.nid) as union_count from {taxonomy_index} ti where tid = :tid_a or tid = :tid_b";
     $result_union = db_query($sql_union, $placeholders);
     
-    foreach($result_union as $record) {
-    	$union_count = $record->union_count;
+    foreach ($result_union as $record) {
+      $union_count = $record->union_count;
     } 
     taxonomy_nco_analysis_db_write($tid_a, $tid_b, $intersection_count, $union_count); // write to DB
    // watchdog('debug', 'intersection: '. $intersection_count . ' union: '. $union_count);
@@ -741,7 +741,13 @@ function taxonomy_nco_analysis_report_status() {
   $running = variable_get('taxonomy_nco_analysis_running', -1);
   $processing = variable_get('taxonomy_nco_analysis_processing', -1);
   $last_processed = variable_get('taxonomy_nco_analysis_last_term_processed', -1);
-  drupal_set_message('taxonomy_nco running:' . $running . ' processing: ' . $processing . ' last seed processed: ' . $last_processed . ' number of seeds: ' . sizeof($seed_terms));
+  drupal_set_message(t('taxonomy_nco running: @running processing: @processing last seed processed: @last_processed number of seeds: @sizeof_seed_terms',
+                        array('@running' => $running,
+                              '@processing' => $processing,
+                              '@last_processed' => $last_processed,
+                              '@sizeof_seed_terms' => sizeof($seed_terms),
+                             )
+                     ));
 }
 
 
@@ -774,7 +780,7 @@ function taxonomy_nco_analysis_tids_to_names($tids) {
  * @param $nco
  * @return unknown_type
  */
-function taxonomy_nco_force($tid_a = null, $tid_b = null, $nco = null) {
+function taxonomy_nco_force($tid_a = NULL, $tid_b = NULL, $nco = NULL) {
   if ($tid_a && $tid_b && !is_null($nco)) {
     taxonomy_nco_force_similar_terms($tid_a, $tid_b, $nco);
   }
@@ -793,7 +799,7 @@ function taxonomy_nco_force($tid_a = null, $tid_b = null, $nco = null) {
  * @todo Please document this function.
  * @see http://drupal.org/node/1354
  */
-function taxonomy_nco_browse($tid_a = null, $limit = 100) {
+function taxonomy_nco_browse($tid_a = NULL, $limit = 100) {
 
   $header = array(
     array(
@@ -850,7 +856,7 @@ function taxonomy_nco_browse($tid_a = null, $limit = 100) {
  * @todo Please document this function.
  * @see http://drupal.org/node/1354
  */
-function taxonomy_nco_cluster_test($tid = null, $nco_local = TAXONOMY_NCO_CLUSTERING_NCO_LOCAL, $power = TAXONOMY_NCO_CLUSTERING_POWER) {
+function taxonomy_nco_cluster_test($tid = NULL, $nco_local = TAXONOMY_NCO_CLUSTERING_NCO_LOCAL, $power = TAXONOMY_NCO_CLUSTERING_POWER) {
   if ($tid) {
     $term = taxonomy_term_load($tid);
     $clusters = taxomomy_nco_clustering_clusters_calculate(array((array) $term), $nco_local, $power);
@@ -890,7 +896,7 @@ function taxonomy_nco_cluster_test($tid = null, $nco_local = TAXONOMY_NCO_CLUSTE
  * @todo Please document this function.
  * @see http://drupal.org/node/1354
  */
-function taxonomy_nco_cluster_size($country = null, $limit = 100) {
+function taxonomy_nco_cluster_size($country = NULL, $limit = 100) {
   $members = _soe_explore_top_subjects($limit);
   $output = theme('table', array('header' => array('count', 'tid', 'name'), 'rows' => $members));
   return $output;
@@ -900,7 +906,7 @@ function taxonomy_nco_cluster_size($country = null, $limit = 100) {
  * @todo Please document this function.
  * @see http://drupal.org/node/1354
  */
-function taxonomy_nco_force_root($tid = null) {
+function taxonomy_nco_force_root($tid = NULL) {
   if ($tid) {
     taxonomy_nco_clustering_add_root($tid);
   }
@@ -995,12 +1001,12 @@ function taxonomy_nco_force_root_single_form_submit($form, &$form_state) {
  * @todo Please document this function.
  * @see http://drupal.org/node/1354
  */
-function taxonomy_nco_cluster_rebuild($go = false, $nco_local = TAXONOMY_NCO_CLUSTERING_NCO_LOCAL, $power = TAXONOMY_NCO_CLUSTERING_POWER, $remote_power = TAXONOMY_NCO_CLUSTERING_REMOTE_POWER) {
+function taxonomy_nco_cluster_rebuild($go = FALSE, $nco_local = TAXONOMY_NCO_CLUSTERING_NCO_LOCAL, $power = TAXONOMY_NCO_CLUSTERING_POWER, $remote_power = TAXONOMY_NCO_CLUSTERING_REMOTE_POWER) {
   if ($go) {
     drupal_set_time_limit(0);
     $count = taxonomy_nco_clustering_term_usage_count();
     $clusters = taxomomy_nco_clustering_clusters_calculate_all($count, $nco_local, $power, $remote_power);
-    taxonomy_nco_clustering_clusters_insert($clusters, true);
+    taxonomy_nco_clustering_clusters_insert($clusters, TRUE);
     $output .= l("View tree", "admin/config/taxonomy_nco_analysis/tree/$nco_local/$power/$remote_power");
     return $output;
   }
