diff --git a/subpathauto.module b/subpathauto.module
index f259cd1..8b28615 100644
--- a/subpathauto.module
+++ b/subpathauto.module
@@ -106,31 +106,24 @@ function subpathauto_lookup_subpath($action, $path = '', $original_path, $path_l
 
   $args = arg(NULL, $path);
   $depth = min($max_depth, substr_count($path, '/'));
-  //$depth = min($max_depth, count($args));
-  $path_len = drupal_strlen($path);
-  $slash_pos = $path_len;
+  $base_parts = explode('/', $path);
+  $sub_parts = array();
 
   // Perform a search for each base path with the right-most segment removed.
-  //$base_paths = array();
   for ($i = 1; $i <= $depth; $i++) {
-    //dpm("$path - $slash_pos");
-    $slash_pos = strrpos($path, '/', $path_len - $slash_pos);
-    $base_path = substr($path, 0, $slash_pos);
-    $sub_path  = substr($path, $slash_pos + 1);
-    //dpm("$path - $slash_pos - $base_path - $sub_path");
-    //$base_path = implode('/', array_slice($args, 0, -$i));
-    //$sub_path = implode('/', array_slice($args, -$i));
-    //$base_paths[$base_path] = $sub_path;
+    $sub_parts[] = array_pop($base_parts);
+    $base_path = implode('/', $base_parts);
+
     if ($action == 'alias') {
       $aliased_base_path = drupal_get_path_alias($base_path, $path_language);
       if ($aliased_base_path != $base_path) {
-        return $aliased_base_path . '/' . $sub_path;
+        return $aliased_base_path . '/' . implode('/', $sub_parts);
       }
     }
     elseif ($action == 'source') {
-      $sourced_base_path = drupal_get_normal_path($base_path, $path_language);
-      if ($sourced_base_path != $base_path) {
-        return $sourced_base_path . '/' . $sub_path;
+      $sourced_base_path = drupal_lookup_path($action, $base_path, $path_language);
+      if ($sourced_base_path !== FALSE && $sourced_base_path != $base_path) {
+        return $sourced_base_path . '/' . implode('/', $sub_parts);
       }
     }
   }
