diff --git a/uc_restrict_qty.info b/uc_restrict_qty.info
index 6e279d8..197c990 100644
--- a/uc_restrict_qty.info
+++ b/uc_restrict_qty.info
@@ -2,4 +2,4 @@ name = UC Restrict Qty
 description = Restrict the quantity on specified products so that only specified quantity may be purchased at a time.
 dependencies[] = uc_cart
 package = Ubercart - extra
-core = 6.x
\ No newline at end of file
+core = 7.x
diff --git a/uc_restrict_qty.install b/uc_restrict_qty.install
index 09729ae..536fd2e 100644
--- a/uc_restrict_qty.install
+++ b/uc_restrict_qty.install
@@ -6,7 +6,7 @@
  */
 
 /**
- * Define the table structures.
+ * Implements hook_schema().
  *
  * @return
  *   The schema which contains the structure for the uc_restrict_qty module's tables.
@@ -64,28 +64,17 @@ function uc_restrict_qty_schema() {
   return $schema;
 }
 
-
-/**
- * Implementation of hook_install().
- *
- * Inserts the uc_restrict_qty module's schema in the SQL database.
- */
-function uc_restrict_qty_install() {
-  drupal_install_schema('uc_restrict_qty');
-}
-
 /**
- * Implementation of hook_uninstall().
+ * Implements hook_uninstall().
  *
  * Remove the variables and schema corresponding to the uc_restrict_qty module.
  */
 function uc_restrict_qty_uninstall() {
-  drupal_uninstall_schema('uc_restrict_qty');
   db_query("DELETE FROM {variable} WHERE name LIKE 'uc_restrict_qty_%%'");
 }
 
 /**
- * Implementation of hook_update_N().
+ * Implements hook_update_N().
  *
  * If updating from an earlier version than 6.x-2.0, the database needs to be installed.
  */
diff --git a/uc_restrict_qty.module b/uc_restrict_qty.module
index 4e1cbb4..9f5a39a 100644
--- a/uc_restrict_qty.module
+++ b/uc_restrict_qty.module
@@ -19,9 +19,9 @@ function uc_restrict_qty_theme() {
 }
 
 /**
- * Implementation of hook_product_feature().
+ * Implementation of hook_uc_product_feature().
  */
-function uc_restrict_qty_product_feature() {
+function uc_restrict_qty_uc_product_feature() {
   $features[] = array(
     'id' => 'restrict_qty',
     'title' => t('Restrict Qty'),
@@ -84,10 +84,10 @@ function uc_restrict_qty_settings_validate($form, &$form_state) {
 }
 
 // Builds the form to display for adding or editing a the restricted quantity feature.
-function uc_restrict_qty_feature_form($form_state, $node, $feature) {
+function uc_restrict_qty_feature_form($form, &$form_state, $node, $feature) {
   $models = uc_product_get_models($node);
   if (!empty($feature)) {
-    $product_qty = db_fetch_object(db_query("SELECT * FROM {uc_restrict_qty_products} WHERE pfid = %d", $feature['pfid']));
+    $product_qty = db_query("SELECT * FROM {uc_restrict_qty_products} WHERE pfid = :pfid", array(':pfid' => $feature['pfid']))->fetchObject();
 
     $default_qty = $product_qty->qty;
     $default_model = $product_qty->model;
@@ -137,7 +137,7 @@ function uc_restrict_qty_feature_form($form_state, $node, $feature) {
     '#description' => t("If checked, user's ordering history will be taken into account too. Useful when you want to prevent double ordering of a product."),
     '#default_value' => isset($default_lifetime) ? $default_lifetime : variable_get('uc_restrict_qty_default_lifetime', FALSE),
   );
-  return uc_product_feature_form($form);
+  return uc_product_feature_form($form, $form_state, $node, $feature);
 }
 
 // Validates the textfield on the product features settings form.
@@ -148,7 +148,12 @@ function uc_restrict_qty_feature_form_validate($form, &$form_state) {
   }
 
   // This feature is already set on this SKU?
-  if ($product_roles = db_fetch_object(db_query("SELECT * FROM {uc_restrict_qty_products} WHERE nid = %d AND model = '%s'", $form_state['values']['nid'], $form_state['values']['model'])) && $form_state['values']['pfid'] == 0) {
+  $product_roles = db_query("SELECT * FROM {uc_restrict_qty_products} WHERE nid = :nid AND model = :model", array(
+    ':nid' => $form_state['values']['nid'],
+    ':model' => $form_state['values']['model'],
+  ))->fetchObject();
+
+  if ($product_roles && $form_state['values']['pfid'] == 0) {
     form_set_error('uc_roles_model', t('A quantity restriction has already been set up for this SKU'));
   }
 }
@@ -156,10 +161,10 @@ function uc_restrict_qty_feature_form_validate($form, &$form_state) {
 /**
  * Form submit handler for the roles feature form.
  */
-function uc_restrict_qty_feature_form_submit($form, &$form_state) {
+function uc_restrict_qty_feature_form_submit($form, &$form_state) {dpm($form_state);
   $product_qty = array(
-    'rqpid'       => $form_state['values']['rqpid'],
-    'pfid'        => $form_state['values']['pfid'],
+    'rqpid'       => isset($form_state['values']['rqpid']) ? $form_state['values']['rqpid'] : NULL,
+    'pfid'        => isset($form_state['values']['pfid']) ? $form_state['values']['pfid'] : NULL,
     'nid'         => $form_state['values']['nid'],
     'model'       => $form_state['values']['model'],
     'qty'         => $form_state['values']['quantity'],
@@ -171,12 +176,15 @@ function uc_restrict_qty_feature_form_submit($form, &$form_state) {
   $description .= '<strong>'. t('Type') .':</strong> '. ($product_qty['lifetime'] ? t('Lifetime') : t('Cart max.')) .'<br/>';
 
   $data = array(
-    'pfid' => $product_qty['pfid'],
     'nid' => $product_qty['nid'],
     'fid' => 'restrict_qty',
     'description' => $description,
   );
 
+  if (isset($product_qty['pfid'])) {
+    $data['pfid'] = $product_qty['pfid'];
+  }
+
   $form_state['redirect'] = uc_product_feature_save($data);
 
   $key = NULL;
@@ -186,7 +194,7 @@ function uc_restrict_qty_feature_form_submit($form, &$form_state) {
 
   // Insert or update uc_file_product table
   if (empty($product_qty['pfid'])) {
-    $product_qty['pfid'] = db_last_insert_id('uc_product_features', 'pfid');
+    $product_qty['pfid'] = $data['pfid'];
   }
 
   drupal_write_record('uc_restrict_qty_products', $product_qty, $key);
@@ -291,9 +299,9 @@ function theme_restrict_qty_field($element) {
 function uc_restrict_qty_count($form_values) {
   global $user;
 
-  $data = db_fetch_array(db_query("SELECT qty, lifetime FROM {uc_restrict_qty_products} WHERE nid = %d", $form_values['nid']));
+  $data = db_query("SELECT qty, lifetime FROM {uc_restrict_qty_products} WHERE nid = :nid", array(':nid' => $form_values['nid']))->fetchAssoc();
   if ($data['lifetime']) {
-    $bought_qty = db_result(db_query('SELECT SUM(uop.qty) FROM {uc_orders} uo LEFT JOIN {uc_order_products} uop ON uo.order_id = uop.order_id WHERE uo.order_status = "completed" AND uo.uid = %d AND uop.nid = %d ORDER BY uop.nid', $user->uid, $form_values['nid']));
+    $bought_qty = db_query('SELECT SUM(uop.qty) FROM {uc_orders} uo LEFT JOIN {uc_order_products} uop ON uo.order_id = uop.order_id WHERE uo.order_status = "completed" AND uo.uid = :uid AND uop.nid = :nid ORDER BY uop.nid', array(':uid' => $user->uid , ':nid' => $form_values['nid']))->fetchField();
     $data['rest'] = $data['qty'] - $bought_qty;
   }
 
@@ -311,15 +319,15 @@ function uc_restrict_qty_count($form_values) {
  *   A Drupal node ID.
  */
 function uc_restrict_qty_node_delete($nid) {
-  db_query("DELETE FROM {uc_restrict_qty_products} WHERE nid = %d", $nid);
+  db_query("DELETE FROM {uc_restrict_qty_products} WHERE nid = :nid", array(':nid' => $nid));
 }
 
 /**
  * Delete all data associated with a given product feature.
  *
  * @param $pfid
- *   An Ubercart product feature ID.
+ *   An Ubercart product feature array.
  */
-function uc_restrict_qty_feature_delete($pfid) {
-  db_query("DELETE FROM {uc_restrict_qty_products} WHERE pfid = %d", $pfid);
-}
\ No newline at end of file
+function uc_restrict_qty_feature_delete($feature) {
+  db_query("DELETE FROM {uc_restrict_qty_products} WHERE pfid = :pfid", array(':pfid' => $feature['pfid']));
+}
