diff --git a/nodehierarchy.module b/nodehierarchy.module
index 57ddea9..c65c222 100644
--- a/nodehierarchy.module
+++ b/nodehierarchy.module
@@ -359,37 +359,49 @@ function nodehierarchy_menu_overview_form($form, &$form_state, $menu) {
  */
 function nodehierarchy_form_menu_edit_item_alter(&$form, &$form_state) {
   // Replace the parent pulldown with the node hierarchy parent selector.
-  if ($form['menu']['#item']['module'] == 'nodehierarchy') {
+  if ($form['module']['#value'] == 'nodehierarchy') {
     // Add the js to hide/show the menu selector.
     drupal_add_js(drupal_get_path("module", "nodehierarchy") . '/nodehierarchy.js');
 
+	$menu = menu_load($form['original_item']['#value']['menu_name']);
+    $item = menu_link_load($form['mlid']['#value']);
+	if (!$item) {
+      $item = array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => $menu['menu_name'], 'weight' => 0, 'link_path' => '', 'options' => array(), 'module' => 'menu', 'expanded' => 0, 'hidden' => 0, 'has_children' => 0);
+    }
+	$menus = menu_get_menus();
+
     // Get the node for this menu item.
-    list(, $nid) = explode('/', $form['menu']['#item']['link_path']);
+    list(, $nid) = explode('/', $form['link_path']['#value']);
     $node = node_load($nid);
 
     // Load the parent menu item if any (to get the parent node id).
-    $parent_menu = _nodehierarchy_load_menu_link($form['menu']['#item']['plid']);
+    $parent_menu = _nodehierarchy_load_menu_link($item['plid']);
+
+    $default = $item['menu_name'] .':'. (isset($item['plid']) ? $item['plid'] : 0);
+    if (!isset($options[$default])) {
+      $default = 'navigation:0';
+    }
 
     // Add a class to the menu fieldset to allow the js to work.
-    $form['menu']['#attributes']['class'] .= ' nodehierarchy-menu-link';
+    $form['#attributes']['class'][] = 'nodehierarchy-menu-link';
 
     // Replace the parent pulldown.
-    $form['menu']['pnid'] = _nodehierarchy_get_parent_selector($node->type, $parent_menu['nid'], $nid);
+    unset($form['parent']);
+    $form['pnid'] = _nodehierarchy_get_parent_selector($node->type, $parent_menu['nid'], $nid);
 
     // Add the menu selector in case the user picks none for the parent.
-    $form['menu']['menu_name'] = array(
+    $form['menu_name'] = array(
       '#type' => 'select',
       '#title' => 'Menu',
       '#prefix' => '<div class="nodehierarchy-menu-name">',
       '#suffix' => '</div>',
-      '#options' => menu_get_menus(),
-      '#default_value' => $form['menu']['#item']['menu_name'],
+      '#options' => $menus,
+      '#default_value' => $default,
       '#description' => t('If you do not pick a parent for this node its menu item will appear at the top level of this menu.'),
     );
     // Set some weights so that the weight pulldown still appears at the bottom.
-    $form['menu']['parent']['#weight'] = 10;
-    $form['menu']['menu_name']['#weight'] = 20;
-    $form['menu']['weight']['#weight'] = 30;
+    $form['menu_name']['#weight'] = 20;
+    $form['weight']['#weight'] = 30;
 
     $form['#submit'] = array_merge(array('nodehierarchy_form_menu_edit_item_submit'), $form['#submit']);
   }
