diff --git a/invoice_ajax.inc b/invoice_ajax.inc
index 8cba571..ade49ab 100755
--- a/invoice_ajax.inc
+++ b/invoice_ajax.inc
@@ -108,10 +108,21 @@ function invoice_get_customer_info() {
 }
 
 /**
- * Add an invoice item
+ * Ajax callback to add an invoice item.
  */
 function invoice_save_item() {
   $fv =& $_POST;
+  $data = invoice_api_save_item($fv);
+  drupal_json_output($data);
+  exit;
+}
+
+/**
+ * Adds an invoice item.
+ * @param  [array] $fv keyed array describing an item.
+ * @return [array]     response array.
+ */
+function invoice_controller_save_item($fv) {
   $data = array();
 
   $fv['invoice_number'] = isset($fv['invoice_number']) ? $fv['invoice_number'] : 0;
@@ -119,8 +130,7 @@ function invoice_save_item() {
   // Check user admin access for this invoice
   if (!_invoice_user_has_admin_access_to_invoice($fv['invoice_number'])) {
     $data['error'] = t('You are not the owner of this item id!');
-    drupal_json_output($data);
-    exit;
+    return $data;
   }
 
   // Set locale so money has the right format for the preferred culture
@@ -154,8 +164,7 @@ function invoice_save_item() {
   }
 
   if (!empty($data['error'])) {
-    drupal_json_output($data);
-    exit;
+    return $data;
   }
 
   // Typecast strings to doubles and replace comma with a dot
@@ -260,8 +269,7 @@ function invoice_save_item() {
   $data['extotal'] = _invoice_round_and_format_money($totals['extotal'], 2);
   $data['inctotal'] = _invoice_round_and_format_money($totals['inctotal'], 2);
 
-  drupal_json_output($data);
-  exit;
+  return $data;
 }
 
 /**
@@ -360,4 +368,4 @@ function invoice_delete_item() {
 
   drupal_json_output($data);
   exit;
-}
\ No newline at end of file
+}
