diff --git a/src/Plugin/views/argument/IndexNameDepth.php b/src/Plugin/views/argument/IndexNameDepth.php
index c6d99b0..092c84c 100644
--- a/src/Plugin/views/argument/IndexNameDepth.php
+++ b/src/Plugin/views/argument/IndexNameDepth.php
@@ -135,62 +135,25 @@ class IndexNameDepth extends ArgumentPluginBase {
   public function query($group_by = FALSE) {
     $this->ensureMyTable();
 
-    if (!empty($this->options['break_phrase'])) {
-      $break = static::breakString($this->argument);
-      if ($break->value === [-1]) {
-        return FALSE;
+    $break = static::breakString($this->argument);
+    if (count($break->value) > 1) {
+      if (!empty($this->options['break_phrase'])) {
+        if ($break->value === [-1]) {
+          return FALSE;
+        }
+        $operator = (count($break->value) > 1) ? 'IN' : '=';
+        $tids = $break->value;
       }
-
-      $operator = (count($break->value) > 1) ? 'IN' : '=';
-      $tids = $break->value;
     }
     else {
-      $operator = "=";
+      $operator = "IN";
       $tids = $this->argument;
     }
 
     // Now build the subqueries.
-    if (is_string($tids)) {
-      if (\Drupal::service('module_handler')->moduleExists('pathauto')) {
-        $query = $this->database->select('taxonomy_term_field_data', 't')
-          ->fields('t', ['tid', 'name']);
-
-        // Filter by vocabulary ID if one or more are provided.
-        if (!empty($this->options['vocabularies'])) {
-          $query->condition('t.vid', $this->options['vocabularies'], 'IN');
-        }
-
-        $results = $query->execute()->fetchAll(\PDO::FETCH_OBJ);
-
-        // Iterate results.
-        foreach ($results as $row) {
-          // Service container for alias cleaner.
-          $alias = \Drupal::service('pathauto.alias_cleaner');
-          if ($alias->cleanString($row->name) == $alias->cleanString($tids)) {
-            $tids = $row->tid;
-          }
-        }
-      }
-      else {
-        // Replaces "-" with space if exist.
-        $argument = str_replace('-', ' ', $tids);
-        $query = $this->database->select('taxonomy_term_field_data', 't')
-          ->fields('t', ['tid', 'name']);
-
-        // Filter by vocabulary ID if one or more are provided.
-        if (!empty($this->options['vocabularies'])) {
-          $query->condition('t.vid', $this->options['vocabularies'], 'IN');
-        }
-
-        $query->condition('t.name', $argument, '=');
-
-        $results = $query->execute()->fetchAll(\PDO::FETCH_OBJ);
-
-        // Iterate results.
-        foreach ($results as $row) {
-          $tids = $row->tid;
-        }
-      }
+    $tids = $this->getTidsFromNames(is_string($tids) ? [$tids] : $tids);
+    if (empty($tids)) {
+      return FALSE;
     }
 
     // Now build the subqueries.
@@ -222,6 +185,45 @@ class IndexNameDepth extends ArgumentPluginBase {
   }
 
   /**
+   * Get the taxonomy term ids from the names.
+   *
+   * @param array $names
+   *   Array of taxonomy names.
+   *
+   * @return array
+   *   Array of entity ids.
+   */
+  protected function getTidsFromNames(array $names) {
+
+    $query = $this->termStorage->getQuery();
+    // Filter by vocabulary ID if one or more are provided.
+    if (!empty($this->options['vocabularies'])) {
+      $query->condition('vid', $this->options['vocabularies'], 'IN');
+    }
+
+    $alias_cleaner = NULL;
+    if (\Drupal::service('module_handler')->moduleExists('pathauto')) {
+      // Service container for alias cleaner.
+      $alias_cleaner = \Drupal::service('pathauto.alias_cleaner');
+    }
+
+    $tids = [];
+    foreach ($this->termStorage->loadMultiple($query->execute()) as $term) {
+      foreach ($names as $name) {
+        if (
+          ($alias_cleaner && $alias_cleaner->cleanString($term->label()) == $alias_cleaner->cleanString($name)) ||
+          (!$alias_cleaner && $term->label() == str_replace('-', ' ', $name))
+        ) {
+          $tids[] = $term->id();
+          break;
+        }
+      }
+    }
+
+    return $tids;
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function title() {
