diff --git a/subpathauto.module b/subpathauto.module
index 4fd2eda..35327a7 100644
--- a/subpathauto.module
+++ b/subpathauto.module
@@ -22,7 +22,11 @@ function subpathauto_menu() {
 function subpathauto_url_inbound_alter(&$path, $original_path, $language) {
   // If the current menu item exists at this path, then we should not continue
   // processing.
-  $item = menu_get_item($path);
+
+  // $item = menu_get_item($path);
+
+  // To avoid: https://www.deeson.co.uk/labs/curious-incident-wrong-theme-being-used-after-cache-clear-drupal-7
+  $item = subpathauto_lightweight_menu_get_item($path);
   if (!empty($item) && $item['href'] == $path) {
     return FALSE;
   }
@@ -33,6 +37,52 @@ function subpathauto_url_inbound_alter(&$path, $original_path, $language) {
 }
 
 /**
+ * Most of the menu_get_item api function but without the menu_rebuild parts.
+ *
+ * @see menu_get_item()
+ */
+function subpathauto_lightweight_menu_get_item($path) {
+  $original_map = arg(NULL, $path);
+  $parts = array_slice($original_map, 0, MENU_MAX_PARTS);
+  $ancestors = menu_get_ancestors($parts);
+  $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc();
+
+  if ($router_item) {
+    $router_item['original_map'] = $original_map;
+
+    // Allow modules to alter the router item.
+    drupal_alter('menu_get_item', $router_item, $path, $original_map);
+
+    // Generate the link path for the page request or local tasks.
+    $link_map = explode('/', $router_item['path']);
+    if (isset($router_item['tab_root'])) {
+      $tab_root_map = explode('/', $router_item['tab_root']);
+    }
+    if (isset($router_item['tab_parent'])) {
+      $tab_parent_map = explode('/', $router_item['tab_parent']);
+    }
+    for ($i = 0; $i < $router_item['number_parts']; $i++) {
+      if ($link_map[$i] == '%') {
+        $link_map[$i] = $path_map[$i];
+      }
+      if (isset($tab_root_map[$i]) && $tab_root_map[$i] == '%') {
+        $tab_root_map[$i] = $path_map[$i];
+      }
+      if (isset($tab_parent_map[$i]) && $tab_parent_map[$i] == '%') {
+        $tab_parent_map[$i] = $path_map[$i];
+      }
+    }
+    $router_item['href'] = implode('/', $link_map);
+    $router_item['tab_root_href'] = implode('/', $tab_root_map);
+    $router_item['tab_parent_href'] = implode('/', $tab_parent_map);
+    $router_item['options'] = array();
+
+  }
+
+  return $router_item;
+}
+
+/**
  * Implements hook_url_outbound_alter().
  */
 function subpathauto_url_outbound_alter(&$path, $options, $original_path) {
