diff --git a/sites/all/modules/menu_icons/menu_icons.module b/sites/all/modules/menu_icons/menu_icons.module
index 0ff8ccf..8d9ffe1 100644
--- a/sites/all/modules/menu_icons/menu_icons.module
+++ b/sites/all/modules/menu_icons/menu_icons.module
@@ -27,22 +27,21 @@ function menu_icons_menu() {
  * Implementation of hook_form_alter().
  */
 function menu_icons_form_alter(&$form, $form_state, $form_id) {
-
   if ($form_id == 'menu_edit_item') {
-    $options = unserialize(db_result(db_query('SELECT options FROM {menu_links} WHERE mlid = %d', $form['menu']['mlid']['#value'])));
+    $options = $form['menu']['#item']['options'];
 
-    $form['icon'] = array(
+    $form['menu']['menu_icon'] = array(
       '#type' => 'fieldset',
       '#weight' => 5,
       '#title' => t('Menu icon settings'),
       '#description' => t('If checked, the following icon will be used as background image for this menu item.'),
       '#attributes' => array('class' => 'theme-settings-bottom'),
+      '#tree' => TRUE,
     );
-    $form['icon']["use_icon_logo"] = array(
+    $form['menu']['menu_icon']['enable'] = array(
       '#type' => 'checkbox',
       '#title' => t('Use an icon'),
       '#default_value' => $options['menu_icon']['enable'],
-      '#tree' => FALSE,
       '#description' => t('Check this if you want this icon to be used.')
     );
 
@@ -52,7 +51,7 @@ function menu_icons_form_alter(&$form, $form_state, $form_id) {
         $preset_options[$preset['presetname']] = $preset['presetname'];
       }
 
-      $form['icon']['imagecache_preset'] = array(
+      $form['menu']['menu_icon']['imagecache_preset'] = array(
         '#type' => 'select',
         '#title' => t('Imagecache preset'),
         '#default_value' => $options['menu_icon']['imagecache_preset'],
@@ -62,24 +61,22 @@ function menu_icons_form_alter(&$form, $form_state, $form_id) {
       );
     }
 
-    $form['icon']['icon_path'] = array(
+    $form['menu']['menu_icon']['path'] = array(
       '#type' => 'textfield',
       '#title' => t('Path to the icon'),
       '#default_value' => (isset($options['menu_icon']['path']) ? $options['menu_icon']['path'] : variable_get('menu_icons_default_icon', drupal_get_path('module', 'menu_icons') .'/images/default_icon.png')),
       '#description' => t('The path to the image you would like to use as a background image for this menu item.')
     );
-    $form['icon']['icon_upload'] = array(
+    $form['menu']['menu_icon']['icon_upload'] = array(
       '#type' => 'file',
       '#title' => t('Upload a new icon image'),
       '#maxlength' => 40,
       '#description' => t("If you don't have direct file access to the server, use this field to upload your icon.")
     );
 
-    $form['submit']['#weight'] = 9;
-    $form['delete']['#weight'] = 10;
-
     $form['#attributes']['enctype'] = 'multipart/form-data';
-    $form['#submit'][] = 'menu_icons_form_submit';
+    // Put our submit first so we can process a file upload if necessary before the menu link is saved
+    array_unshift($form['#submit'], 'menu_icons_form_submit');
   }
   // Add a custom submit callback for imagecache forms.
   if (in_array($form_id, array('imagecache_ui_preset_form', 'imagecache_ui_action_form', 'imagecache_ui_preset_flush_form', 'imagecache_ui_preset_delete_form', 'menu_icons_admin_settings'))) {
@@ -88,11 +85,10 @@ function menu_icons_form_alter(&$form, $form_state, $form_id) {
 }
 
 /**
- * Process the submitted form
+ * Process the submitted form (handle the optional file upload field).
  *
  */
 function menu_icons_form_submit($form, &$form_state) {
-
   // Get the global setings
   $file_validate_image_resolution = (module_exists('imagecache') ? '0x0' : variable_get('menu_icons_file_validate_image_resolution', '45x45'));
 
@@ -100,9 +96,6 @@ function menu_icons_form_submit($form, &$form_state) {
   $directory_path = menu_icons_directory_path();
   file_check_directory($directory_path, FILE_CREATE_DIRECTORY);
 
-  // Store the current icon path
-  $path = $form_state['values']['icon_path'];
-
   // Define the validation settings
   if ($file_validate_image_resolution != '0x0') {
     $validate = array('file_validate_is_image' => array(), 'file_validate_image_resolution' => array($file_validate_image_resolution));
@@ -120,18 +113,35 @@ function menu_icons_form_submit($form, &$form_state) {
     // files table as a temporary file. We'll make a copy and let the garbage
     // collector delete the original upload.
     file_copy($file, $filename, FILE_EXISTS_REPLACE);
-    $path = $filename;
+    $form_state['values']['menu']['menu_icon']['path'] = $filename;
   }
+}
+
+
+/**
+ * Implementation of hook_TYPE_alter().
+ * Updates the class attribute of the link.
+ *
+ */
+function menu_icons_menu_link_alter(&$item) {
+  $mi_options = isset($item['menu_icon']) ? $item['menu_icon'] : $item['options']['menu_icon'];
   
-  $options = unserialize(db_result(db_query('SELECT options FROM {menu_links} WHERE mlid = %d', $form_state['values']['menu']['mlid'])));
-  $options['menu_icon'] = array('enable' => $form_state['values']['use_icon_logo'], 'path' => $path);
+  // Store the current icon path
+  $enable = $mi_options['enable'];
+  $path = $mi_options['path'];
+  
+  $options = $item['options'];
+  $options['menu_icon'] = array(
+    'enable' => $enable, 
+    'path' => $path,
+  );
 
-  if ($form_state['values']['imagecache_preset']) {
-    $options['menu_icon']['imagecache_preset'] = $form_state['values']['imagecache_preset'];
+  if ($mi_options['imagecache_preset']) {
+    $options['menu_icon']['imagecache_preset'] = $mi_options['imagecache_preset'];
   }
 
-  $class = "menu_icon menu-". $form_state['values']['menu']['mlid'];
-  if ($options['menu_icon']['enable'] && !empty($options['menu_icon']['path']) && file_exists($options['menu_icon']['path'])) {
+  $class = "menu_icon menu-". $item['mlid'];
+  if ($enable && !empty($path) && file_exists($path)) {
     if (!strstr($options['attributes']['class'], $class)) {
       $options['attributes']['class'] = (empty($options['attributes']['class']) ? $class : $options['attributes']['class'] . " $class");
     }
@@ -144,12 +154,14 @@ function menu_icons_form_submit($form, &$form_state) {
     unset($options['attributes']['class']);
   }
 
-  db_query('UPDATE {menu_links} SET options = "%s" WHERE mlid = %d', serialize($options), $form_state['values']['menu']['mlid']);
-
+  $item['options'] = $options;
+  
   // Regenerate the css file
   menu_icons_css_generate();
 }
 
+
+
 /**
  * Implementation of hook_init().
  */
