diff --git a/menu_node.install b/menu_node.install
index 698e9a9..15c652c 100644
--- a/menu_node.install
+++ b/menu_node.install
@@ -46,7 +46,7 @@ function menu_node_schema() {
 function menu_node_enable() {
   $result = db_query("SELECT ml.mlid, ml.link_path FROM {menu_links} ml INNER JOIN {menu_custom} mc ON ml.menu_name = mc.menu_name WHERE ml.link_path <> 'node/%' AND ml.router_path = 'node/%'");
   foreach ($result as $data) {
-    $nid = str_replace('node/', '', $data->link_path);
+    $nid = preg_replace('/(node\/)([\d]*)(.*)/', '$2', $data->link_path);
     // Ensure that we did not grab any bad links accidentally.
     $check = (bool) db_query("SELECT COUNT(*) FROM {node} WHERE nid = :nid", array(':nid' => $nid))->fetchField();
     if ($check) {
@@ -120,7 +120,7 @@ function menu_node_update_6003() {
     LEFT JOIN {menu_links} ml ON mn.mlid = ml.mlid WHERE mcount.count > 1 AND ml.router_path LIKE 'node/%%'");
   // Walk through every row and test them based on nid.
   foreach ($result as $data) {
-    $nid = str_replace('node/', '', $data->link_path);
+    $nid = preg_replace('/(node\/)([\d]*)(.*)/', '$2', $data->link_path);
     // Does the stored nid match the menu_link path nid?
     $check = (bool) $nid == $data->nid;
     // If check failed we delete the row with this combination.
diff --git a/menu_node.module b/menu_node.module
index d171bd2..e21ade4 100644
--- a/menu_node.module
+++ b/menu_node.module
@@ -12,10 +12,10 @@
  * Implements hook_menu_link_insert().
  */
 function menu_node_menu_link_insert($link) {
-  if ($link['router_path'] != 'node/%' || !isset($link['mlid'])) {
+  if ($link['router_path'] != 'node/%' && $link['router_path'] != 'node/%/mid/%' || !isset($link['mlid'])) {
     return;
   }
-  $nid = str_replace('node/', '', $link['link_path']);
+  $nid = preg_replace('/(node\/)([\d]*)(.*)/', '$2', $link['link_path']);
   if ($node = node_load($nid)) {
     menu_node_record_save($node, $link);
   }
@@ -25,7 +25,7 @@ function menu_node_menu_link_insert($link) {
  * Implements hook_menu_link_update().
  */
 function menu_node_menu_link_update($link) {
-  if ($link['router_path'] != 'node/%') {
+  if ($link['router_path'] != 'node/%' && $link['router_path'] != 'node/%/mid/%') {
     // new link is NOT attached to a node
     if (menu_node_get_node($link['mlid'])) {
       // old link WAS attached to a node: menu_node record need to be deleted:
@@ -34,7 +34,7 @@ function menu_node_menu_link_update($link) {
   }
   else {
     // new link IS attached to a node
-    $nid = str_replace('node/', '', $link['link_path']);
+    $nid = preg_replace('/(node\/)([\d]*)(.*)/', '$2', $link['link_path']);
     if ($node = node_load($nid)) {
       menu_node_record_save($node, $link);
     }
