diff --git a/uc_free_order.info b/uc_free_order.info
index 0fcae5c..1150f6f 100644
--- a/uc_free_order.info
+++ b/uc_free_order.info
@@ -3,4 +3,4 @@ description = Enables a payment method to handle the possibility of free orders.
 dependencies[] = uc_order
 dependencies[] = uc_payment
 package = Ubercart - payment
-core = 6.x
+core = 7.x
diff --git a/uc_free_order.js b/uc_free_order.js
index 0cbb294..3e34abe 100644
--- a/uc_free_order.js
+++ b/uc_free_order.js
@@ -1,53 +1,59 @@
+(function ($) {
 
-var free_order_initialized = false;
-var using_free_order = false;
+Drupal.behaviors.ucFreeOrder = {
 
-// Adds a click function to the total so we can check its updated values.
-$(document).ready(
-  function() {
-    $('#edit-panes-payment-current-total').click(function() { free_order_check_total(this.value); });
-  }
-);
+	attach: function (context, settings) {
 
-/**
- * Checks the current total and updates the available/selected payment methods
- * accordingly.
- */
-function free_order_check_total(total) {
-  total = parseFloat(total);
+		var free_order_initialized = false;
+		var using_free_order = false;
 
-  // Disable the free order option and select the first available method.
-  if (total >= .005 && (using_free_order != false || free_order_initialized == false)) {
-    // Show the other payment method radios.
-    $("#payment-pane .form-radios input:radio").removeAttr('disabled').parent().show(0);
+		// Our main click handler.
+		// Adds a click function to the total so we can check its updated values.
+//     $('#edit-panes-payment-current-total').click(function() { free_order_check_total(this.value); });
+    $('#line-items-div input').click(function() { free_order_check_total(this.value); });
+		/**
+		* Checks the current total and updates the available/selected payment methods
+		* accordingly.
+		*/
+		function free_order_check_total(total) {
+			total = parseFloat(total);
+      alert(total);
+			// Disable the free order option and select the first available method.
+			if (total >= .005 && (using_free_order != false || free_order_initialized == false)) {
+				// Show the other payment method radios.
+				$("#payment-pane .form-radios input:radio").removeAttr('disabled').parent().show(0);
 
-    // Hide the free order radio.
-    $("input:radio[value=free_order]").attr('disabled', 'disabled').parent().hide(0);
+				// Hide the free order radio.
+				$("input:radio[value=free_order]").attr('disabled', 'disabled').parent().hide(0);
 
-    // Find the first available payment method.
-    var uc_free_order_next_method = $(':radio[name="panes[payment][payment_method]"]:enabled:first').val();
+				// Find the first available payment method.
+				var uc_free_order_next_method = $(':radio[name="panes[payment][payment_method]"]:enabled:first').val();
 
-    // Select the first payment method.
-    $("input:radio[value=" + uc_free_order_next_method + "]").attr('checked', 'checked');
+				// Select the first payment method.
+				$("input:radio[value=" + uc_free_order_next_method + "]").attr('checked', 'checked');
 
-    // Refresh the payment details section.
-    get_payment_details(Drupal.settings.ucURL.checkoutPaymentDetails + uc_free_order_next_method);
+				// Refresh the payment details section.
+				get_payment_details(Drupal.settings.ucURL.checkoutPaymentDetails + uc_free_order_next_method);
 
-    using_free_order = false;
-  }
-  else if (total < .005 && using_free_order != true) {
-    // Hide the fallback payment method radio.
-    $("#payment-pane .form-radios input:radio").attr('disabled', 'disabled').parent().hide(0);
+				using_free_order = false;
+			}
+			else if (total < .005 && using_free_order != true) {
+				// Hide the fallback payment method radio.
+				$("#payment-pane .form-type-radios input:radio").attr('disabled', 'disabled').parent().hide(0);
 
-    // Show and select the free order payment method.
-    $("input:radio[value=free_order]").removeAttr('disabled').attr('checked', 'checked').parent().show(0);
+				// Show and select the free order payment method.
+				$("input:radio[value=free_order]").removeAttr('disabled').attr('checked', 'checked').parent().show(0);
 
-    // Refresh the payment details section.
-    get_payment_details(Drupal.settings.ucURL.checkoutPaymentDetails + 'free_order');
+				// Refresh the payment details section.
+				get_payment_details(Drupal.settings.ucURL.checkoutPaymentDetails + 'free_order');
 
-    using_free_order = true;
-  }
+				using_free_order = true;
+			}
 
-  free_order_initialized = true;
-}
+			free_order_initialized = true;
+		}
+	}
 
+};
+
+})(jQuery);
diff --git a/uc_free_order.module b/uc_free_order.module
index 6b48e13..eb4faf9 100644
--- a/uc_free_order.module
+++ b/uc_free_order.module
@@ -7,42 +7,48 @@
 
 
 /**
- * Implementation of hook_perm().
+ * Implementation of hook_permission().
  */
-function uc_free_order_perm() {
-  return array('test free order');
+function uc_free_order_permission() {
+  return array(
+    'test free order' => array(
+      'title' => t('Test Free Order Functionality'),
+    ),
+  );
 }
-
 /**
- * Implementation of hook_form_alter().
+ * Implementation of hook_form_FORM_ID_alter().
  */
-function uc_free_order_form_alter(&$form, &$form_state, $form_id) {
-  global $user;
-
-  // Alter the checkout form to prepare it for our special JS.
-  if ($form_id == 'uc_cart_checkout_form' && isset($form['panes']['payment'])) {
-    if (user_access('test free order')) {
-      drupal_set_message('Test free order: <span style="cursor: pointer;" onclick="alert(\'Discount added.\'); set_line_item(\'fo_discount\', \'Test Discount\', -2000, 0);">Add discount</span> | <span style="cursor: pointer;" onclick="alert(\'Discount removed.\'); remove_line_item(\'fo_discount\');">Remove discount</span>');
-    }
-
-    drupal_add_js(drupal_get_path('module', 'uc_free_order') .'/uc_free_order.js');
+function uc_free_order_form_uc_cart_checkout_form_alter(&$form, &$form_state, $form_id) {
+  if (!user_access('test free order')) {
+    return;
   }
-  elseif ($form_id == 'uc_cart_checkout_review_form') {
-    $order = uc_order_load($_SESSION['cart_order']);
-
-    if ($order->payment_method == 'free_order') {
-      if ($order->order_total >= .01) {
-        drupal_set_message(t('We cannot process your order without payment.'), 'error');
-        drupal_goto('cart/checkout');
-      }
-    }
+  $order = $form['panes']['payment']['line_items']['#order'];
+  if ($order->order_total >= 0.01) {
+    unset($form['panes']['payment']['payment_method']['#options']['free_order']);
+    return;
+  }
+  $free_order = $form['panes']['payment']['payment_method']['#options']['free_order'];
+  $form['panes']['payment']['payment_method']['#options'] = array(
+    'free_order' => $free_order);
+}
+function uc_free_order_form_uc_cart_checkout_review_form_alter(&$form, &$form_state, $form_id) {
+  $order = uc_order_load($_SESSION['cart_order']);
+//   dsm($order);
+//   dsm($form);
+  if ($order->payment_method != 'free_order') {
+    return;
+  }
+  if ($order->order_total >= 0.01) {
+    drupal_set_message(t('We cannot process your order without payment.'), 'error');
+    drupal_goto('cart/checkout');
   }
 }
 
 /**
- * Implementation of hook_payment_method().
+ * Implementation of hook_uc_payment_method().
  */
-function uc_free_order_payment_method() {
+function uc_free_order_uc_payment_method() {
   $methods[] = array(
     'id' => 'free_order',
     'name' => t('Free order'),
@@ -51,14 +57,14 @@ function uc_free_order_payment_method() {
     'callback' => 'uc_payment_method_free_order',
     'checkout' => TRUE,
     'no_gateway' => TRUE,
-    'weight' => 10,
+    'weight' => -10,
   );
 
   return $methods;
 }
 
 // Handles the free order payment method.
-function uc_payment_method_free_order($op, &$arg1, $silent = FALSE) {
+function uc_payment_method_free_order($op, &$order) {
   if ($op == 'cart-details') {
     return t('Continue with checkout to complete your free order.');
   }
