diff --git a/uc_atctweaks/uc_atctweaks.info b/uc_atctweaks/uc_atctweaks.info
index c56b1b6..3d5d2ac 100644
--- a/uc_atctweaks/uc_atctweaks.info
+++ b/uc_atctweaks/uc_atctweaks.info
@@ -5,12 +5,15 @@ description = Defines a product feature to tweak the add to cart form behavior.
 dependencies[] = uc_cart
 dependencies[] = uc_product
 package = Ubercart - extra
-core = 6.x
+core = 7.x
 php = 5.0
 
 ; Information added by drupal.org packaging script on 2009-05-19
 version = "6.x-1.0-rc1"
-core = "6.x"
+core = 7.x
 project = "uc_atctweaks"
 datestamp = "1242760580"
 
+
+files[] = uc_atctweaks.install
+files[] = uc_atctweaks.module
diff --git a/uc_atctweaks/uc_atctweaks.install b/uc_atctweaks/uc_atctweaks.install
index 1a7389a..fcf1981 100644
--- a/uc_atctweaks/uc_atctweaks.install
+++ b/uc_atctweaks/uc_atctweaks.install
@@ -6,6 +6,9 @@
  * Installs the necessary table for the Add to Cart Tweaks product features.
  */
 
+/**
+ * Implementation of hook_schema()
+ */
 function uc_atctweaks_schema() {
   $schema = array();
 
@@ -23,14 +26,14 @@ function uc_atctweaks_schema() {
         'default' => 0,
       ),
       'cart_empty' => array(
-        'description' => t('Cart empty setting for this instance of the feature.'),
+        'description' => 'Cart empty setting for this instance of the feature.',
         'type' => 'int',
         'size' => 'small',
         'not null' => TRUE,
         'default' => 0,
       ),
       'redirect' => array(
-        'description' => t('Add to cart redirect for this instance of the feature.'),
+        'description' => 'Add to cart redirect for this instance of the feature.',
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
@@ -46,11 +49,11 @@ function uc_atctweaks_schema() {
   return $schema;
 }
 
-function uc_atctweaks_install() {
-  drupal_install_schema('uc_atctweaks');
-}
-
+/**
+ * Implementation of hook_uninstall()
+ */
 function uc_atctweaks_uninstall() {
-  drupal_uninstall_schema('uc_atctweaks');
-  db_query("DELETE FROM {uc_product_features} WHERE fid = 'atctweaks'");
+  db_delete('uc_product_features')
+    ->condition('fid', 'atctweaks')
+    ->execute();
 }
diff --git a/uc_atctweaks/uc_atctweaks.module b/uc_atctweaks/uc_atctweaks.module
index c357d13..a604a02 100644
--- a/uc_atctweaks/uc_atctweaks.module
+++ b/uc_atctweaks/uc_atctweaks.module
@@ -1,6 +1,4 @@
 <?php
-// $Id: uc_atctweaks.module,v 1.1 2009/05/19 18:53:48 rszrama Exp $
-
 /**
  * @file
  * Defines a product feature to tweak the add to cart form behavior.
@@ -8,7 +6,7 @@
 
 
 /**
- * Implementation of hook_form_alter().
+ * Implements hook_form_alter().
  *
  * Summary of alterations:
  * 1) Alters the product feature add form to restrict multiple Add to Cart
@@ -20,7 +18,7 @@ function uc_atctweaks_form_alter(&$form, &$form_state, $form_id) {
   // 1) Alter the product feature add form.
   if ($form_id == 'uc_product_feature_add_form') {
     // If an add to cart tweak has already been added to this product...
-    if (db_result(db_query("SELECT COUNT(*) FROM {uc_product_features} WHERE nid = %d AND fid = '%s'", arg(1), 'atctweaks'))) {
+    if (db_query("SELECT COUNT(*) FROM {uc_product_features} WHERE nid = :nid AND fid = :fid", array(':nid' => arg(1), ':fid' => 'atctweaks'))->fetchField()) {
       // Remove Add to Cart Tweak from the available list of features to add.
       unset($form['feature']['#options']['atctweaks']);
     }
@@ -42,13 +40,12 @@ function uc_atctweaks_form_alter(&$form, &$form_state, $form_id) {
 
   // 3) Alter the product class form to set default add to cart tweaks.
   if ($form_id == 'uc_product_class_form') {
-    $data = variable_get('ucatc_class_def_'. $form['pcid']['#value'], array());
-
-    if (!empty($data)) {
-      $data = (object) unserialize($data);
-    }
-    else {
-      $data = FALSE;
+    $data = FALSE;
+    if (!empty($form['pcid']['#value'])) {
+      $class_defaults = variable_get('ucatc_class_def_' . $form['pcid']['#value'], array());
+      if (!empty($class_defaults)) {
+        $data = (object) unserialize($class_defaults);
+      }
     }
 
     $form['atctweaks'] = array(
@@ -71,7 +68,9 @@ function uc_atctweaks_form_alter(&$form, &$form_state, $form_id) {
   }
 }
 
-// Submit handler for the add to cart form to process after the normal handler.
+/**
+ * Submit handler for the add to cart form to process after the normal handler.
+ */
 function uc_atctweaks_add_to_cart_pre_submit($form, &$form_state) {
   if (!empty($form_state['values']['atctweaks_data'])) {
     $data = $form_state['values']['atctweaks_data'];
@@ -83,7 +82,9 @@ function uc_atctweaks_add_to_cart_pre_submit($form, &$form_state) {
   }
 }
 
-// Submit handler for the add to cart form to process after the normal handler.
+/**
+ * Submit handler for the add to cart form to process after the normal handler.
+ */
 function uc_atctweaks_add_to_cart_post_submit($form, &$form_state) {
   if (!empty($form_state['values']['atctweaks_data'])) {
     $data = $form_state['values']['atctweaks_data'];
@@ -96,7 +97,7 @@ function uc_atctweaks_add_to_cart_post_submit($form, &$form_state) {
         $form_state['redirect'] = 'cart/checkout';
         break;
       case 'none':
-        $form_state['redirect'] = 'node/'. $form_state['values']['nid'];
+        $form_state['redirect'] = 'node/' . $form_state['values']['nid'];
         break;
       case 'global':
       default:
@@ -105,7 +106,9 @@ function uc_atctweaks_add_to_cart_post_submit($form, &$form_state) {
   }
 }
 
-// Submit handler for the product class form for default Variable Price features.
+/**
+ * Submit handler for the product class form for default Variable Price features.
+ */
 function uc_atctweaks_product_class_submit($form, &$form_state) {
   if ($form_state['values']['default_atctweaks']) {
     $data = array(
@@ -113,23 +116,20 @@ function uc_atctweaks_product_class_submit($form, &$form_state) {
       'redirect' => $form_state['values']['redirect'],
     );
 
-    variable_set('ucatc_class_def_'. $form_state['values']['pcid'], serialize($data));
+    variable_set('ucatc_class_def_' . $form_state['values']['pcid'], serialize($data));
   }
   else {
-    variable_del('ucatc_class_def_'. $form_state['values']['pcid']);
+    variable_del('ucatc_class_def_' . $form_state['values']['pcid']);
   }
 }
 
 /**
- * Implementation of hook_nodeapi().
- *
- * Summary of alterations:
- * 1) Inserts add to cart tweak product feature on product node creation.
+ * Implements hook_node_insert().
+ * Inserts add to cart tweak product feature on product node creation.
  */
-function uc_atctweaks_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
-  // When a product node is created...
-  if ($op == 'insert' && uc_product_is_product($node)) {
-    $data = variable_get('ucatc_class_def_'. $node->type, array());
+function uc_atctweaks_node_insert($node) {
+  if (uc_product_is_product($node)) {
+    $data = variable_get('ucatc_class_def_' . $node->type, array());
 
     // If the product class has default Add to Cart Tweaks...
     if ($data) {
@@ -146,9 +146,9 @@ function uc_atctweaks_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
 }
 
 /**
- * Implementation of hook_product_feature().
+ * Implements hook_uc_product_feature().
  */
-function uc_atctweaks_product_feature() {
+function uc_atctweaks_uc_product_feature() {
   $features = array();
 
   $features[] = array(
@@ -162,12 +162,20 @@ function uc_atctweaks_product_feature() {
   return $features;
 }
 
-// Settings form for individual Add to Cart Tweaks.
-function uc_atctweaks_feature_form($form_state, $node, $feature) {
-  $form = array();
-
+/**
+ * Settings form for individual Add to Cart Tweaks.
+ */
+function uc_atctweaks_feature_form($form, &$form_state, $node, $feature) {
   // Load the Add to Cart Tweaks specific to this product.
-  $data = db_fetch_object(db_query("SELECT * FROM {uc_atctweaks_products} WHERE pfid = %d", $feature['pfid']));
+  if (!empty($feature)) {
+    $atctweaks_feature = db_query('SELECT * FROM {uc_atctweaks_products} WHERE pfid = :pfid', array(':pfid' => $feature['pfid']))->fetchObject();
+  }
+  else {
+    $atctweaks_feature = new stdClass();
+    $atctweaks_feature->pfid = '';
+    $atctweaks_feature->cart_empty = FALSE;
+    $atctweaks_feature->redirect = 'global';
+  }
 
   $form['nid'] = array(
     '#type' => 'value',
@@ -175,21 +183,21 @@ function uc_atctweaks_feature_form($form_state, $node, $feature) {
   );
   $form['pfid'] = array(
     '#type' => 'value',
-    '#value' => $data ? $data->pfid : '',
+    '#value' => $atctweaks_feature->pfid,
   );
 
-  $form += _uc_atctweaks_feature_form($data);
+  $form += _uc_atctweaks_feature_form($atctweaks_feature);
 
-  return uc_product_feature_form($form);
+  return $form;
 }
 
-function _uc_atctweaks_feature_form($data = FALSE) {
+function _uc_atctweaks_feature_form($atctweaks_feature = FALSE) {
   $form = array();
 
   $form['cart_empty'] = array(
     '#type' => 'checkbox',
     '#title' => t('Empty the shopping cart of all other items when this product is added to it.'),
-    '#default_value' => $data ? $data->cart_empty : FALSE,
+    '#default_value' => $atctweaks_feature ? $atctweaks_feature->cart_empty : FALSE,
   );
   $form['redirect'] = array(
     '#type' => 'radios',
@@ -200,15 +208,18 @@ function _uc_atctweaks_feature_form($data = FALSE) {
       'checkout' => t('Checkout form'),
       'none' => t('No redirect'),
     ),
-    '#default_value' => $data ? $data->redirect : 'global',
+    '#default_value' => $atctweaks_feature ? $atctweaks_feature->redirect : 'global',
   );
 
   return $form;
 }
 
+/**
+ * @see uc_atctweaks_feature_form()
+ */
 function uc_atctweaks_feature_form_submit($form, &$form_state) {
   // Build an array of Add to Cart Tweaks data from the form submission.
-  $vp_data = array(
+  $atctweaks_data = array(
     'pfid' => $form_state['values']['pfid'],
     'cart_empty' => $form_state['values']['cart_empty'],
     'redirect' => $form_state['values']['redirect'],
@@ -218,16 +229,16 @@ function uc_atctweaks_feature_form_submit($form, &$form_state) {
   $tweaks_form = _uc_atctweaks_feature_form();
 
   $description = array(
-    t('<b>Add to cart form redirect:</b> @redirect', array('@redirect' => $tweaks_form['redirect']['#options'][$vp_data['redirect']])),
+    t('<b>Add to cart form redirect:</b> @redirect', array('@redirect' => $tweaks_form['redirect']['#options'][$atctweaks_data['redirect']])),
   );
 
-  if ($vp_data['cart_empty']) {
+  if ($atctweaks_data['cart_empty']) {
     $description[] = t('The cart will be emptied prior to adding this item to it.');
   }
 
   // Save the basic product feature data.
   $data = array(
-    'pfid' => $vp_data['pfid'],
+    'pfid' => $atctweaks_data['pfid'],
     'nid' => $form_state['values']['nid'],
     'fid' => 'atctweaks',
     'description' => implode('<br />', $description),
@@ -235,26 +246,40 @@ function uc_atctweaks_feature_form_submit($form, &$form_state) {
 
   $form_state['redirect'] = uc_product_feature_save($data);
 
+  $atctweaks_data['pfid'] = $data['pfid'];
+
   // Insert or update the data in the Variable Price products table.
-  if (empty($data['pfid'])) {
-    $vp_data['pfid'] = db_last_insert_id('uc_product_features', 'pfid');
-    $key = NULL;
-  }
-  else {
-    $vp_data['vpid'] = db_result(db_query("SELECT vpid FROM {uc_atctweaks_products} WHERE pfid = %d", $data['pfid']));
+  $key = array();
+  if ($vpid = _uc_atctweaks_get_vpid($atctweaks_data['pfid'])) {
     $key = 'vpid';
+    $atctweaks_data['vpid'] = $vpid;
   }
 
-  drupal_write_record('uc_atctweaks_products', $vp_data, $key);
+  drupal_write_record('uc_atctweaks_products', $atctweaks_data, $key);
 }
 
-// Add to Cart Tweaks product feature delete function.
+/**
+ * Add to Cart Tweaks product feature delete function.
+ */
 function uc_atctweaks_feature_delete($feature) {
-  db_query("DELETE FROM {uc_atctweaks_products} WHERE pfid = %d", $feature['pfid']);
+  db_delete('uc_atctweaks_products')
+    ->condition('pfid', $feature['pfid'])
+    ->execute();
 }
 
-// Load the product feature data for a given node.
+/**
+ * Load the product feature data for a given node.
+ */
 function uc_atctweaks_product_load($nid) {
-  return db_fetch_object(db_query("SELECT atc.* FROM {uc_product_features} AS pf LEFT JOIN {uc_atctweaks_products} AS atc ON pf.pfid = atc.pfid WHERE pf.fid = 'atctweaks' AND pf.nid = %d", $nid));
+  return db_query('SELECT atc.* FROM {uc_product_features} AS pf
+                   LEFT JOIN {uc_atctweaks_products} AS atc ON pf.pfid = atc.pfid
+                   WHERE pf.fid = :pf_fid AND pf.nid = :pf_nid',
+                   array(':pf_fid' => 'atctweaks', ':pf_nid' => $nid))->fetchObject();
 }
 
+/**
+ * Gets a uc_atctweaks id from a product feature id.
+ */
+function _uc_atctweaks_get_vpid($pfid) {
+  return db_query('SELECT vpid FROM {uc_atctweaks_products} WHERE pfid = :pfid', array(':pfid' => $pfid))->fetchField();
+}
