diff -urp node_find_replace_old/node_find_replace.info node_find_replace/node_find_replace.info
--- node_find_replace_old/node_find_replace.info	2009-04-21 18:49:17.000000000 -0500
+++ node_find_replace/node_find_replace.info	2009-04-21 18:50:08.000000000 -0500
@@ -1,8 +1,8 @@
 ; $Id: node_find_replace.info,v 1.1.2.3 2008/05/10 05:00:56 regx Exp $
 name = Node Find Replace
 description = Allows global find and replace on node content.
-; Information added by drupal.org packaging script on 2008-07-26
-version = "5.x-1.3"
+
+version = "6.x-1.3"
 project = "node_find_replace"
-datestamp = "1217081416"
 
+core = 6.x
diff -urp node_find_replace_old/node_find_replace.install node_find_replace/node_find_replace.install
--- node_find_replace_old/node_find_replace.install	2009-04-21 18:51:19.000000000 -0500
+++ node_find_replace/node_find_replace.install	2009-04-21 18:50:30.000000000 -0500
@@ -1,39 +1,107 @@
 <?php
 // $Id: node_find_replace.install,v 1.1.2.7 2008/07/26 14:02:53 regx Exp $
 
+
+/**
+ * Implementation of hook_schema().
+ */
+function node_find_replace_schema() {
+  $schema['node_find_replace_history'] = array(
+    'description' => 'History of node_find_replace Changes',
+    'fields' => array(
+      'hid' => array(
+        'description' => 'History id',
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'key1_name' => array(
+        'description' => 'TODO',
+        'type' => 'varchar',
+        'length' => 256,
+        'not null' => FALSE,
+      ),
+      'key1_value' => array(
+        'description' => 'TODO',
+        'type' => 'varchar',
+        'length' => 256,
+        'not null' => FALSE,
+      ),
+      'key2_name' => array(
+        'description' => 'TODO',
+        'type' => 'varchar',
+        'length' => 256,
+        'not null' => FALSE,
+      ),
+      'key2_value' => array(
+        'description' => 'TODO',
+        'type' => 'varchar',
+        'length' => 256,
+        'not null' => FALSE,
+      ),
+      'key3_name' => array(
+        'description' => 'TODO',
+        'type' => 'varchar',
+        'length' => 256,
+        'not null' => FALSE,
+      ),
+      'key3_value' => array(
+        'description' => 'TODO',
+        'type' => 'varchar',
+        'length' => 256,
+        'not null' => FALSE,
+      ),
+      'table_name' => array(
+        'description' => 'TODO',
+        'type' => 'varchar',
+        'length' => 256,
+        'not null' => FALSE,
+      ),
+      'field_name' => array(
+        'description' => 'TODO',
+        'type' => 'varchar',
+        'length' => 256,
+        'not null' => FALSE,
+      ),
+      'old_value' => array(
+        'description' => 'TODO',
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE,
+      ),
+      'new_value' => array(
+        'description' => 'TODO',
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE,
+      ),
+      'find_string' => array(
+        'description' => 'TODO',
+        'type' => 'varchar',
+        'length' => 256,
+        'not null' => FALSE,
+      ),
+      'replace_string' => array(
+        'description' => 'TODO',
+        'type' => 'varchar',
+        'length' => 256,
+        'not null' => FALSE,
+      ),
+    ),
+    'primary key' => array('hid'),
+  );
+
+  return $schema;
+}
+
 function node_find_replace_install(){
-  $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("CREATE TABLE {node_find_replace_history} (
-        id int(11) NOT NULL auto_increment,
-        hid int(11) NOT NULL default '0',
-        key1_name varchar(256),
-        key1_value varchar(256),
-        key2_name varchar(256),
-        key2_value varchar(256),
-        key3_name varchar(256),
-        key3_value varchar(256),
-        table_name varchar(256) default NULL,
-        field_name varchar(256) default NULL,
-        old_value longtext,
-        new_value longtext,
-        find_string varchar(256) default NULL,
-        replace_string varchar(256) default NULL,
-        timestamp timestamp NULL default NULL on update CURRENT_TIMESTAMP,
-        PRIMARY KEY (id)
-        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"
-      );
-    break;
-    default:
-    drupal_set_message(t('Only Mysql and Mysqli are supported'),'error');
-  }
+  drupal_install_schema('node_find_replace'); 
   return $ret;
 }
 
 
 function node_find_replace_uninstall() {
-  db_query('DROP TABLE {node_find_replace_history}');
+  // Remove tables.
+  drupal_uninstall_schema('node_find_replace');
+
   db_query('DELETE from {system} where name = "node_find_replace"');
 }
diff -urp node_find_replace_old/node_find_replace.module node_find_replace/node_find_replace.module
--- node_find_replace_old/node_find_replace.module	2009-04-21 18:51:31.000000000 -0500
+++ node_find_replace/node_find_replace.module	2009-04-21 18:50:42.000000000 -0500
@@ -36,34 +36,21 @@ Description:
 
 define('NODE_FIND_REPLACE_DEBUG', 0);
 
-/**
- * Implementation of hook_simpletest().
- */
-function node_find_replace_simpletest() {
-  $dir = drupal_get_path('module', 'node_find_replace'). '/test';
-  $tests = file_scan_directory($dir, '\.test');
-  return array_keys($tests);
-}
-//---------------------------------------------------
-
-
 
 /**
  * Implementation of hook_menu().
  */
-function node_find_replace_menu($may_cache) {
+function node_find_replace_menu() {
   global $user;
   $items = array();
 
-  //if ($may_cache) {
-
-    $items[] = array('path' => 'admin/content/node_find_replace',
-      'title' => t('Node Find Replace'),
-      'description' => t('Perform global find/replace on content.'),
-      'access' => user_access('administer nodes'),
-      'callback' => 'node_find_replace_form',
+    $items['admin/content/node_find_replace'] = array(
+      'title' => 'Node Find Replace',
+      'description' => 'Perform global find/replace on content.',
+      'access arguments' => array('administer nodes'),
+      'page callback' => 'node_find_replace_form',
      );
-  //}
+
   return $items;
 }
 
@@ -71,9 +58,9 @@ function node_find_replace_menu($may_cac
 /**
  * Implementation of hook_help
  */
-function node_find_replace_help($section)
+function node_find_replace_help($path, $arg)
 {
-	switch($section) {
+	switch($path) {
 		case 'admin/modules#description':
 			return t('Allows global find and replace on nodes.');
 	}
@@ -86,7 +73,7 @@ function node_find_replace_form() {
   return $output;
 }
 
-function node_find_replace_search_form(){
+function node_find_replace_search_form(&$form_state){
   $form['find_replace'] = array(
     '#type' => 'fieldset',
     '#title' => t('Find Replace'),
@@ -140,7 +127,7 @@ function node_find_replace_search_form()
   return $form;
 }
 
-function node_find_replace_history_form(){
+function node_find_replace_history_form(&$form_state){
 $form = array();
   
   $form['find_replace_history'] = array(
@@ -165,7 +152,7 @@ $form = array();
   $form['find_replace_history']['row']['hid'] = array(
     '#type' => 'radios',
     '#title' => 'History ID',
-    '#required' => TRUE,
+    '#required' => FALSE,
     '#options' => $history_options,
   );
     
@@ -181,21 +168,29 @@ $form = array();
     '#type' => 'submit',
     '#value' => t('Delete History'),
   );
+ $form['find_replace_history']['delete_all_history'] = array(
+    '#type' => 'submit',
+    '#value' => t('Delete All History'),
+  );
   return $form;
 }
-function node_find_replace_history_form_submit($form_id, $form_values){
+function node_find_replace_history_form_submit($form, &$form_state){
   switch($_POST['op']){
     case 'Undo':
-      node_find_replace_history_undo($form_values['hid']);
+      node_find_replace_history_undo($form_state['values']['hid']);
       break;
     
     case 'Redo':
-      node_find_replace_history_redo($form_values['hid']);
+      node_find_replace_history_redo($form_state['values']['hid']);
       break;
     
     case 'Delete History':
-      node_find_replace_history_delete($form_values['hid']);
+      node_find_replace_history_delete($form_state['values']['hid']);
       break;
+	
+	case 'Delete All History':
+	  node_find_replace_history_delete_all();
+	  break;
   }
   
   node_find_replace_clear_cache();
@@ -263,45 +258,48 @@ function node_find_replace_history_delet
   drupal_set_message("hid:$hid Deleted",'status');
 }
 
-function node_find_replace_search_form_validate($form_id, $form_values) {
-  if(!$form_values['find_string']){
+function node_find_replace_history_delete_all(){
+  db_query("DELETE FROM {node_find_replace_history}");
+  drupal_set_message("Node Find Replace History Deleted",'status');
+}
+
+
+function node_find_replace_search_form_validate($form, &$form_state) {
+  if(!$form_state['values']['find_string']){
     form_set_error('find_string', t('Find String can not be blank.'));
   }
-  if(!$form_values['replace_string']){
+  if(!$form_state['values']['replace_string']){
     form_set_error('replace_string', t('Replace String can not be blank.'));
   }
 }
 
-function node_find_replace_search_form_submit($form_id, $form_values) {
+function node_find_replace_search_form_submit($form, &$form_state) {
   //node_find_replace_debug('submit');
   $match_count = 0;
   $node_replace_count = 0;
 
-  $find_string = $form_values['find_string'];
-  $replace_string = $form_values['replace_string'];
+  $find_string = $form_state['values']['find_string'];
+  $replace_string = $form_state['values']['replace_string'];
   $replace_count = 0;
-
-  $hid = db_next_id('node_find_replace_history_hid');
   
-  if($form_values['checkbox_findreplace_nodetitles'] == 1){
-    find_replace_node_titles($hid,$find_string,$replace_string);
+  if($form_state['values']['checkbox_findreplace_nodetitles'] == 1){
+    find_replace_node_titles($find_string, $replace_string);
   }
-  if($form_values['checkbox_findreplace_nodebodies'] == 1){
-    find_replace_node_bodies($hid,$find_string,$replace_string);
+  if($form_state['values']['checkbox_findreplace_nodebodies'] == 1){
+    find_replace_node_bodies($find_string, $replace_string);
   }
-  if($form_values['checkbox_findreplace_ccknodes'] == 1){
-    find_replace_cck_nodes($hid,$find_string,$replace_string);
+  if($form_state['values']['checkbox_findreplace_ccknodes'] == 1){
+    find_replace_cck_nodes($find_string, $replace_string);
   }
-  if($form_values['checkbox_findreplace_blocks'] == 1){
-    find_replace_blocks($hid,$find_string,$replace_string);
+  if($form_state['values']['checkbox_findreplace_blocks'] == 1){
+    find_replace_blocks($find_string, $replace_string);
   }
   node_find_replace_clear_cache();
-  
-  return 'admin/content/node_find_replace';
+ 
+ $form_state['redirect'] =  'admin/content/node_find_replace';
 }
-//---------------------------------------------------------
 
-function find_replace_node_titles($hid,$find_string,$replace_string){
+function find_replace_node_titles($find_string,$replace_string){
   $title_count = 0;
   $sql = "select * from {node_revisions} where title like '%s';"; 
   $result = db_query($sql,'%'.$find_string.'%');
@@ -311,63 +309,11 @@ function find_replace_node_titles($hid,$
       $title_count ++;
       $new_val = str_replace($find_string,$replace_string,$row['title']);
       
-      /* @annotation: todo: refactor save history sql to seperate function */
-      
       # save history for `revision title`
-      $id = db_next_id('node_find_replace_history_id');
-      db_query("INSERT INTO {node_find_replace_history} SET 
-        id = %d,
-        hid = %d,
-        key1_name = 'nid',
-        key1_value = %d,
-        key2_name = 'vid',
-        key2_value = %d,
-        table_name = '%s',
-        field_name = '%s',
-        old_value = '%s',
-        new_value = '%s',
-        find_string = '%s',
-        replace_string = '%s';"
-        ,
-        $id,
-        $hid,
-        $row['nid'],
-        $row['vid'],
-        'node_revisions',
-        'title',
-        $row['title'],
-        $new_val,
-        $find_string,
-        $replace_string
-      );
-      
+      $return = find_replace_save_history('nid', $row['nid'], 'vid', $row['vid'], NULL, NULL, 'node_revisions', 'title', $row['title'], $new_val, $find_string, $replace_string);
+	  
       # save history for `node title`
-      $id = db_next_id('node_find_replace_history_id');
-      db_query("INSERT INTO {node_find_replace_history} SET 
-        id = %d,
-        hid = %d,
-        key1_name = 'nid',
-        key1_value = %d,
-        key2_name = 'vid',
-        key2_value = %d,
-        table_name = '%s',
-        field_name = '%s',
-        old_value = '%s',
-        new_value = '%s',
-        find_string = '%s',
-        replace_string = '%s';"
-        ,
-        $id,
-        $hid,
-        $row['nid'],
-        $row['vid'],
-        'node',
-        'title',
-        $row['title'],
-        $new_val,
-        $find_string,
-        $replace_string
-      );
+     $return = find_replace_save_history('nid', $row['nid'], 'vid', $row['vid'], NULL, NULL, 'node', 'title', $row['title'], $new_val, $find_string, $replace_string);
 
       # replace revision title
       db_query("UPDATE {node_revisions} set
@@ -390,11 +336,10 @@ function find_replace_node_titles($hid,$
     }
   }
   drupal_set_message($title_count . ' node title revisions replaced','status');
-  watchdog('Node_Find_Replace',"hid:$hid replaced $title_count node title revisions");
+  watchdog('Node_Find_Replace',"Replaced $title_count node title revisions");
 }
-//---------------------------------------------------------
 
-function find_replace_blocks($hid,$find_string,$replace_string){
+function find_replace_blocks($find_string,$replace_string){
   $block_body_count = 0;
   $block_desc_count = 0;
   $block_title_count = 0;
@@ -407,32 +352,8 @@ function find_replace_blocks($hid,$find_
       $block_body_count ++;
       $new_val = str_replace($find_string,$replace_string,$row['body']);
       
-      /* @annotation: todo: refactor save history sql to seperate function */
-      
       # save history for boxes.body
-      $id = db_next_id('node_find_replace_history_id');
-      db_query("INSERT INTO {node_find_replace_history} SET 
-        id = %d,
-        hid = %d,
-        key1_name = 'bid',
-        key1_value = %d,
-        table_name = '%s',
-        field_name = '%s',
-        old_value = '%s',
-        new_value = '%s',
-        find_string = '%s',
-        replace_string = '%s';"
-        ,
-        $id,
-        $hid,
-        $row['bid'],
-        'boxes',
-        'body',
-        $row['body'],
-        $new_val,
-        $find_string,
-        $replace_string
-      );
+      $return = find_replace_save_history('bid', $row['bid'], NULL, NULL, NULL, NULL, 'boxes', 'body', $row['body'], $new_val, $find_string, $replace_string);
       
       # replace boxes.body
       db_query("UPDATE {boxes} set
@@ -455,32 +376,8 @@ function find_replace_blocks($hid,$find_
       $block_desc_count ++;
       $new_val = str_replace($find_string,$replace_string,$row['info']);
       
-      /* @annotation: todo: refactor save history sql to seperate function */
-      
       # save history for boxes.info
-      $id = db_next_id('node_find_replace_history_id');
-      db_query("INSERT INTO {node_find_replace_history} SET 
-        id = %d,
-        hid = %d,
-        key1_name = 'bid',
-        key1_value = %d,
-        table_name = '%s',
-        field_name = '%s',
-        old_value = '%s',
-        new_value = '%s',
-        find_string = '%s',
-        replace_string = '%s';"
-        ,
-        $id,
-        $hid,
-        $row['bid'],
-        'boxes',
-        'info',
-        $row['info'],
-        $new_val,
-        $find_string,
-        $replace_string
-      );
+      $return = find_replace_save_history('bid', $row['bid'], NULL, NULL, NULL, NULL, 'boxes', 'info', $row['info'], $new_val, $find_string, $replace_string);
       
       # replace boxes.info
       db_query("UPDATE {boxes} set
@@ -503,38 +400,8 @@ function find_replace_blocks($hid,$find_
       $block_title_count ++;
       $new_val = str_replace($find_string,$replace_string,$row['title']);
       
-      /* @annotation: todo: refactor save history sql to seperate function */
-      
       # save history for blocks.title
-      $id = db_next_id('node_find_replace_history_id');
-      db_query("INSERT INTO {node_find_replace_history} SET 
-        id = %d,
-        hid = %d,
-        key1_name = 'module',
-        key1_value = '%s',
-        key2_name = 'delta',
-        key2_value = '%s',
-        key3_name = 'theme',
-        key3_value = '%s',
-        table_name = '%s',
-        field_name = '%s',
-        old_value = '%s',
-        new_value = '%s',
-        find_string = '%s',
-        replace_string = '%s';"
-        ,
-        $id,
-        $hid,
-        $row['module'],
-        $row['delta'],
-        $row['theme'],
-        'blocks',
-        'title',
-        $row['title'],
-        $new_val,
-        $find_string,
-        $replace_string
-      );
+      $return = find_replace_save_history('module', $row['module'], 'delta', $row['delta'], 'theme', $row['theme'], 'node_revisions', 'title', $row['title'], $new_val, $find_string, $replace_string);
       
       # replace blocks.title
       db_query("UPDATE {blocks} set
@@ -554,12 +421,12 @@ function find_replace_blocks($hid,$find_
   drupal_set_message("$block_body_count block bodies replaced",'status');
   drupal_set_message("$block_desc_count block descriptions replaced",'status');
   drupal_set_message("$block_title_count block titles replaced",'status');
-  watchdog('Node_Find_Replace',"hid:$hid replaced $block_body_count block bodies, $block_desc_count block descriptions and $block_title_count block titles");
+  watchdog('Node_Find_Replace',"Replaced $block_body_count block bodies, $block_desc_count block descriptions and $block_title_count block titles");
 }
 
 
-function find_replace_node_bodies($hid,$find_string,$replace_string){
-  $body_count = 0; # body count - hah!
+function find_replace_node_bodies($find_string,$replace_string){
+  $body_count = 0;
   $sql = "select * from {node_revisions} where body like '%s';"; 
   $result = db_query($sql,'%'.$find_string.'%');
 
@@ -568,36 +435,9 @@ function find_replace_node_bodies($hid,$
       $body_count ++;
       $new_val = str_replace($find_string,$replace_string,$row['body']);
       
-      /* @annotation: todo: refactor save history sql to seperate function */
-      
       # save data for `revision body`
-      $id = db_next_id('node_find_replace_history_id');
-      db_query("INSERT INTO {node_find_replace_history} SET 
-        id = %d,
-        hid = %d,
-        key1_name = 'nid',
-        key1_value = %d,
-        key2_name = 'vid',
-        key2_value = %d,
-        table_name = '%s',
-        field_name = '%s',
-        old_value = '%s',
-        new_value = '%s',
-        find_string = '%s',
-        replace_string = '%s';"
-        ,
-        $id,
-        $hid,
-        $row['nid'],
-        $row['vid'],
-        'node_revisions',
-        'body',
-        $row['body'],
-        $new_val,
-        $find_string,
-        $replace_string
-      );
-
+	  $return = find_replace_save_history('nid', $row['nid'], 'vid', $row['vid'], NULL, NULL, 'node_revisions', 'body', $row['body'], $new_val, $find_string, $replace_string);
+      
       # replace revision body
       db_query("UPDATE {node_revisions} set
         body = '%s' where
@@ -610,32 +450,7 @@ function find_replace_node_bodies($hid,$
       );
       
       #replace teasers
-      $id = db_next_id('node_find_replace_history_id');
-      db_query("INSERT INTO {node_find_replace_history} SET 
-        id = %d,
-        hid = %d,
-        key1_name = 'nid',
-        key1_value = %d,
-        key2_name = 'vid',
-        key2_value = %d,
-        table_name = '%s',
-        field_name = '%s',
-        old_value = '%s',
-        new_value = '%s',
-        find_string = '%s',
-        replace_string = '%s';"
-        ,
-        $id,
-        $hid,
-        $row['nid'],
-        $row['vid'],
-        'node_revisions',
-        'teaser',
-        $row['teaser'],
-        $new_val,
-        $find_string,
-        $replace_string
-      );
+      $return = find_replace_save_history('nid', $row['nid'], 'vid', $row['vid'], NULL, NULL, 'node_revisions', 'teaser', $row['teaser'], $new_val, $find_string, $replace_string);
       
       # replace revision teaser body
       db_query("UPDATE {node_revisions} set
@@ -651,11 +466,10 @@ function find_replace_node_bodies($hid,$
 
   }
   drupal_set_message($body_count . ' node body revisions replaced','status');
-  watchdog('Node_Find_Replace',"hid:$hid replaced $body_count node body revisions");
+  watchdog('Node_Find_Replace',"Replaced $body_count node body revisions");
 }
-//----------------------------------------------------------
 
-function find_replace_cck_nodes($hid,$find_string,$replace_string){
+function find_replace_cck_nodes($find_string,$replace_string){
   $cck_count = 0;
   if(module_exists('content')){
   
@@ -680,7 +494,7 @@ function find_replace_cck_nodes($hid,$fi
               //node_find_replace_debug($cck_field);
               
               /** Replace CCK content **/
-              $sql = "select * from {%s} where %s like '%s';"; 
+              $sql = "select * from %s where %s like '%s';"; 
               $result = db_query($sql,$cck_table,$cck_field,'%'.$find_string.'%');
             
               while($row = db_fetch_array($result)){
@@ -689,32 +503,7 @@ function find_replace_cck_nodes($hid,$fi
                   $new_val = str_replace($find_string,$replace_string,$row["$cck_field"]);
                   
                   #save history for cck content
-                  $id = db_next_id('node_find_replace_history_id');
-                  db_query("INSERT INTO {node_find_replace_history} SET 
-                    id = %d,
-                    hid = %d,
-                    key1_name = 'nid',
-                    key1_value = %d,
-                    key2_name = 'vid',
-                    key2_value = %d,
-                    table_name = '%s',
-                    field_name = '%s',
-                    old_value = '%s',
-                    new_value = '%s',
-                    find_string = '%s',
-                    replace_string = '%s';"
-                    ,
-                    $id,
-                    $hid,
-                    $row['nid'],
-                    $row['vid'],
-                    $cck_table,
-                    $cck_field,
-                    $row["$cck_field"],
-                    $new_val,
-                    $find_string,
-                    $replace_string
-                  );
+                  $return = find_replace_save_history('nid', $row['nid'], 'vid', $row['vid'], NULL, NULL, $cck_table, $cck_field, $row['$cck_field'], $new_val, $find_string, $replace_string);
             
                   # replace revision
                   db_query("UPDATE {%s} set
@@ -738,11 +527,27 @@ function find_replace_cck_nodes($hid,$fi
 
   }
     drupal_set_message($cck_count . ' cck fields replaced','status');
-    watchdog('Node_Find_Replace',"hid:$hid replaced $cck_count cck fields");
+    watchdog('Node_Find_Replace',"Replaced $cck_count cck fields");
 }
-###########################################################################
-
 
+function find_replace_save_history($key1_name, $key1_value, $key2_name, $key2_value, $key3_name, $key3_value, $table_name, $field_name, $old_value, $new_value, $find_string, $replace_string) {
+	$table = 'node_find_replace_history';
+	$record = new stdClass();
+	$record->key1_name = $key1_name;
+	$record->key1_value = $key1_value;
+	$record->key2_name = $key2_name;
+	$record->key2_value = $key2_value;
+	$record->key3_name = $key3_name;
+	$record->key3_value = $key3_value;
+	$record->table_name = $table_name;
+	$record->field_name = $field_name;
+	$record->old_value = $old_value;
+	$record->new_value = $new_value;
+	$record->find_string = $find_string;
+	$record->replace_string = $replace_string;
+	$return = drupal_write_record($table, $record);
+	return $return;
+}
 
 # Helper Functions
 function node_find_replace_clear_cache(){
