diff -up /Users/alex/Desktop/term_merge/term_merge.info term_merge/term_merge.info
--- /Users/alex/Desktop/term_merge/term_merge.info	2009-04-27 08:28:10.000000000 -0400
+++ term_merge/term_merge.info	2010-02-02 14:05:39.000000000 -0500
@@ -1,3 +1,5 @@
+; $Id$
+
 name = "Term Merge"
 description = "Offers ability to merge all the items tagged with term A and all those with term B."
 dependencies[] = taxonomy
@@ -8,5 +10,4 @@ core = 6.x
 version = "6.x-1.x-dev"
 core = "6.x"
 project = "term_merge"
-datestamp = "1240835290"
-
+datestamp = "1240835290"
\ No newline at end of file
diff -up /Users/alex/Desktop/term_merge/term_merge.module term_merge/term_merge.module
--- /Users/alex/Desktop/term_merge/term_merge.module	2009-04-27 00:21:16.000000000 -0400
+++ term_merge/term_merge.module	2010-02-02 14:05:19.000000000 -0500
@@ -1,153 +1,144 @@
 <?php
+// $Id$
 
 /**
-* term_merge.module by Eli Dickinson - eli (-at-) fiercemarkets.com
-* Based on Merging_Terms.txt by Aldo Hoeben (see http://drupal.org/node/113975)
-* Version 0.1 - 2007-05-10
-* 
-* Experimental Drupal 6 support added 2009-04-27
-*
-*
-* 	This module creates a new link at the bottom of the Edit Term form that lets 
-*		you merge the displayed term with another term. All nodes from the old term
-*		will be tagged with the new term.
-*
-*		 
-*/
+ * term_merge.module by Eli Dickinson - eli (-at-) fiercemarkets.com
+ * Based on Merging_Terms.txt by Aldo Hoeben (see http://drupal.org/node/113975)
+ * Version 0.1 - 2007-05-10
+ * 
+ * Experimental Drupal 6 support added 2009-04-27
+ *
+ *
+ *   This module creates a new link at the bottom of the Edit Term form that lets 
+ *    you merge the displayed term with another term. All nodes from the old term
+ *    will be tagged with the new term.
+ *
+ */
 
 /**
-* Implementation of hook_help().
-*/
+ * Implementation of hook_help().
+ */
 function term_merge_help($path, $arg) {
   switch($path) {
     case 'admin/modules#description':
-      return t('Allows site admins to merge two terms, making one a synonym of another.');
+      return t('Allows site admins to merge two terms, making one a synonym of the other.');
   }
 }
 
 /**
-* Implementation of hook_menu()
-*/
+ * Implementation of hook_menu()
+ */
 function term_merge_menu() {
   $items = array();
 
-	$items['term_merge/merge'] = array(
-	  'title' => 'Merges one Term into anothers',
-	  'access arguments' => array('administer taxonomy'),
-	  'type' => MENU_CALLBACK,
-	  'page callback' => 'term_merge_merge'
-	 );    
+  $items['term_merge/merge'] = array(
+    'title' => 'Merges one Term into another',
+    'access arguments' => array('administer taxonomy'),
+    'type' => MENU_CALLBACK,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('term_merge_merge_form'),
+   );
   return $items;
-} 
-
-
-
-function term_merge_merge($from_tid) { 
-	return drupal_get_form('term_merge_merge_form',$from_tid);	
 }
 
-
 /**
  * Presents the form to select which node to merge into.
  */
 function term_merge_merge_form(&$form_state, $tid){
-	//$form[] = array('#value' => $tid);
-	$from_term = taxonomy_get_term($tid);
-	$from_name = check_plain($from_term->name);
-	$term = taxonomy_get_term($tid);
-	$form['from_tid'] = array('#type' => 'value', '#value' => $tid);
-	
-	$form['to_tid'] = _taxonomy_term_select(t("Merge all '$from_name' items into"), 'to_tid', -1, $term->vid, '', FALSE, NULL, array($tid));
-	$form['submit'] = array('#type' => 'submit', '#value' => t('Merge'));
+  $from_term = taxonomy_get_term($tid);
+  $from_name = check_plain($from_term->name);
+  $term = taxonomy_get_term($tid);
+  $form['from_tid'] = array('#type' => 'value', '#value' => $tid);
+  
+  $form['to_tid'] = _taxonomy_term_select(t("Merge all '$from_name' items into"), 'to_tid', -1, $term->vid, '', FALSE, NULL, array($tid));
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Merge'));
   $form['info'] = array('#value' => "<p>As a result of this operation, '$from_name' will be deleted and all the nodes tagged with '$from_name' will now be tagged with the selection in the box above. In addition '$from_name' will be listed as a synonym for the selected node.</p><p>Note that this operation is not reversible!</p>");
-	return $form;
+  return $form;
 }
 
 /**
  * Actually merges the terms 
  */
-function term_merge_merge_form_submit($form, &$form_state) { 
-	//print implode(",",$form_state['values']);
-	$to_term = taxonomy_get_term($form_state['values']['to_tid']);
-	$from_term = taxonomy_get_term($form_state['values']['from_tid']);
-
-	$old_max_exec = ini_get('max_execution_time');
-	if ($old_max_exec < 30) $old_max_exec = 30;
-	set_time_limit(100);
-
-	// Copy any Synonyms from from_term to to_term.
-	// I'd love to do this with a Drupal func, but taxonomy_save_term() looks like way more trouble than it's worth
-	db_query("INSERT INTO {term_synonym} (tid, name) (SELECT '%d',name from {term_synonym} where tid = '%d')", $to_term->tid, $from_term->tid);
-	//TODO: This could lead to duplicate synonyms.
-	
-	
-
-	// save a list of nodes we need to update to new term
-	$nodes_to_update = _term_merge_select_nodes($from_term->tid);
-	
-	// Add from_node as a synonym to to_node to prevent future duplication
-	db_query("INSERT INTO {term_synonym} (tid, name) VALUES (%d, '%s')", $to_term->tid, $from_term->name);
-	//TODO: This could lead to duplicate synonyms.
-	
-	// update old nodes to new nodes
+function term_merge_merge_form_submit($form, &$form_state) {
+  $old_max_exec = ini_get('max_execution_time');
+  if ($old_max_exec < 30) $old_max_exec = 30;
+  set_time_limit(100);
+  
+  $to_tid = $form_state['values']['to_tid'];
+  $from_tid = $form_state['values']['from_tid'];
+
+  $to_term = taxonomy_get_term($to_tid);
+  $from_term = taxonomy_get_term($from_tid);
+  $merged_syn = array_unique(array_merge(taxonomy_get_synonyms($to_tid), taxonomy_get_synonyms($from_tid), array($from_term->name)));  
+
+  $merged = (array)$to_term;
+  $merged['synonyms'] = implode("\n",$merged_syn);
+  $merged['relations'] = taxonomy_get_related($to_tid);
+  $merged['parent'] = array();
+  
+  $parents = taxonomy_get_parents($to_tid);
+  foreach ($parents as $parent){
+    $merged['parent'][] = $parent->tid;
+  }
+
+  taxonomy_save_term($merged);
+
+  // save a list of nodes we need to update to new term
+  $nodes_to_update = _term_merge_select_nodes($from_term->tid);
+
+  // update old nodes to new nodes
   while ($node_record = db_fetch_object($nodes_to_update)) {
     $node = node_load($node_record->nid); // gotta use node_load to get the taxonomies in there
     $save_node_changes = TRUE;
     $new_taxonomy = array();
     foreach ($node->taxonomy as $term) {
-    	if ($term->tid == $to_term->tid) {
-    		// If the node already has the destination tag, we don't need to change a thing! 
-    		// (taxonomy_del_term will take care of removing the old tag)
-    		$save_node_changes = FALSE;
-    		break;
-    	}
-    	
-    	if ($term->tid == $from_term->tid) {
-    		$new_taxonomy[] = $to_term; // make the switch!
-    	} else {
-    		$new_taxonomy[] = $term;
-    	}
-    	
+      if ($term->tid == $to_term->tid) {
+        // If the node already has the destination tag, we don't need to change a thing! 
+        // (taxonomy_del_term will take care of removing the old tag)
+        $save_node_changes = FALSE;
+        break;
+      }
+
+      if ($term->tid == $from_term->tid) {
+        $new_taxonomy[] = $to_term; // make the switch!
+      } else {
+        $new_taxonomy[] = $term;
+      }
+      
+    }
+
+    if ($save_node_changes) {
+      taxonomy_node_save($node, $new_taxonomy);
     }
-    		
-  	if ($save_node_changes)
-  		taxonomy_node_save($node, $new_taxonomy);
-    // note for 6.x: taxonomy_node_save was changed to take a $node object instead of $nid
   }
-	
-	taxonomy_del_term($from_term->tid);
-	
-	set_time_limit($old_max_exec);
-	
-	drupal_set_message(t('The terms have been merged. Have a great day.'));
-	$form_state['redirect'] = 'admin/content/taxonomy/' . $to_term->vid;
-}
 
+  taxonomy_del_term($from_term->tid);
 
+  set_time_limit($old_max_exec);
+
+  drupal_set_message(t('The term <em>@from</em> has been merged into <em>@to</em>. Have a great day.', array('@to' => $to_term->name, '@from' => $from_term->name)));
+  $form_state['redirect'] = 'admin/content/taxonomy/' . $to_term->vid;
+}
 
 /**
-* Implementation of hook_form_alter().
-*/
+ * Implementation of hook_form_alter().
+ */
 
 function term_merge_form_alter(&$form, &$form_state, $form_id) {
- 	
   // Add the link to the term edit form
   if ($form_id == 'taxonomy_form_term') {
-  	
-  	$tid = $form['tid']['#value'];
-  	//$tid= arg(5);
-		$form['merge'] = array( '#value' => '<div><strong>' . l(t('Merge this term into another another'),"term_merge/merge/$tid") . '</strong></div>' );
+    $tid = $form['tid']['#value'];
+    //$tid= arg(5);
+    $form['merge'] = array( '#value' => '<div><strong>' . l(t('Merge this term into another another'),"term_merge/merge/$tid") . '</strong></div>' );
   }
-  
 }
 
 /**
- *	Returns the results of a query for nodes associated for the specified $tid. (Thanks, Aldo!)
+ *  Returns the results of a query for nodes associated for the specified $tid. (Thanks, Aldo!)
  */
 function _term_merge_select_nodes($tid) { 
-  // I would have liked to use taxonomy_select_nodes() instead, but that function
-  // either uses a pager, or returns only the latest n nodes, and we need all of them 
-  // (including unpublished nodes)
+  // I would have liked to use taxonomy_select_nodes() instead,
+  // but we need all nodes including unpublished ones.
 
   // generate an array of descendant term IDs to the right depth.
   $descendant_tids = array();
@@ -159,9 +150,5 @@ function _term_merge_select_nodes($tid) 
   $str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));
   $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .')';
 
-  $result = db_query(db_rewrite_sql($sql));
-
-  return $result;
-} 
-
-?>
\ No newline at end of file
+  return db_query(db_rewrite_sql($sql));
+}
\ No newline at end of file
