Index: sites/default/modules/menuperformance/menuperformance.module
===================================================================
--- sites/default/modules/menuperformance/menuperformance.module	(revision 587)
+++ sites/default/modules/menuperformance/menuperformance.module	(working copy)
@@ -101,7 +101,7 @@
         ),
       ),
     );
-		
+
 		if (module_exists('disable_node_menu_item')) {
 			$form['menu']['link']['link_disabled'] = array(
         '#type' => 'checkbox',
@@ -109,7 +109,7 @@
         '#description' => t('Select this option to create the menu item, but hide it from the menu tree. This may be useful to keep your content structured without cluttering the menu for site visitors.'),
         '#default_value' => (!empty($link['hidden']) ? $link['hidden'] : (empty($form['#node']->nid)?1:0)),
       );
-      
+
       $form['#submit'][] = 'disable_node_menu_item_submit';
 		}
 
@@ -147,7 +147,7 @@
     // Use the currently selected menu item's parent as the default parent
     // item, if a menu link has been defined. Otherwise, use the root element
     // of the menu defined for this content type.
-    
+
     $default = variable_get('menu_options_' . $type, array('main-menu'));
     $default = reset($default);
     $default_value = ($link['mlid'] ? $link['menu_name'] . ':' . $link['plid'] : $default . ':0');
@@ -210,6 +210,7 @@
   else {
     $available_menus = menu_get_menus();
   }
+
   // Add the select element for the menu selection.
   $form['parent_menu'] = array(
     '#type' => 'select',
@@ -275,10 +276,13 @@
     }
   }
 
-  for ($i = 0; $i <= count($temp_items); $i++) {
-    $item = array_pop($temp_items);
-    $item['#attributes']['data-mpi'] = $i;
-    $form['menuperformance_node_menu_parent_link_' . $i] = $item;
+  $i_tmp = 0;
+  if (!empty($temp_items)) {
+    foreach ( array_reverse($temp_items) as $item) {
+      $i_tmp++;
+      $item['#attributes']['data-mpi'] = $i_tmp;
+      $form['menuperformance_node_menu_parent_link_' . $i_tmp] = $item;
+    }
   }
 
   $form['parent_container_end'] = array(
@@ -431,8 +435,13 @@
   $query = db_select('menu_links')
   ->fields('menu_links', array('link_title', 'mlid'))
   ->condition('plid', $mlid)
-  ->condition('menu_name', $menu_name);
+  ->condition('menu_name', $menu_name)
+  ->orderBy('weight', 'ASC');
 
+  for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
+    $query->orderBy('p' . $i, 'ASC');
+  }
+
   $result = $query->execute();
 
   $children = array();
