diff --git a/pathauto_persist.module b/pathauto_persist.module
index 15804e1..de10d47 100644
--- a/pathauto_persist.module
+++ b/pathauto_persist.module
@@ -4,9 +4,29 @@
  * Implements hook_entity_load().
  */
 function pathauto_persist_entity_load($entities, $type) {
+  static $drupal_static_fast;
+
+  if (!isset($drupal_static_fast)) {
+    $drupal_static_fast['types'] = &drupal_static(__FUNCTION__);
+  }
+
+  $path_auto_entity_types = &$drupal_static_fast['types'];
+
+  // Save the entity types used statically to avoid unnecessary queries later.
+  if (!isset($path_auto_entity_types)) {
+    $path_auto_entity_types = db_query("SELECT entity_type FROM {pathauto_persist} GROUP BY entity_type")->fetchAllKeyed(0, 0);
+  }
+
+  // We aren't storing state for this type at the moment.
+  if (!isset($path_auto_entity_types[$type])) {
+    return;
+  }
   $states = pathauto_persist_entity_state_load_multiple($type, array_keys($entities));
   foreach ($states as $id => $state) {
     if (!isset($entities[$id]->path['pathauto'])) {
+      if (!isset($entities[$id]->path) || !is_array($entities[$id]->path)) {
+        $entities[$id]->path = array();
+      }
       $entities[$id]->path['pathauto'] = $state;
     }
   }
@@ -63,7 +83,35 @@ function pathauto_persist_entity_state_load($entity_type, $entity_id) {
  *   An array of entity IDs.
  */
 function pathauto_persist_entity_state_load_multiple($entity_type, $entity_ids) {
-  $pathauto_state = db_query("SELECT entity_id, pathauto FROM {pathauto_persist} WHERE entity_type = :entity_type AND entity_id IN (:entity_ids)", array(':entity_type' => $entity_type, ':entity_ids' => $entity_ids))->fetchAllKeyed();
+  static $table_exists;
+
+  if (!isset($table_exists)) {
+    $table_exists = db_table_exists('pathauto_persist');
+  }
+
+  if (!$table_exists) {
+    if (!defined('MAINTENANCE_MODE')) {
+      $message = t('The <code>pathauto_state</code> table does not exist, so a default value was provided. Please make sure to run <code>update.php</code>');
+      drupal_set_message($message, 'warning');
+      watchdog('pathauto', $message, array(), WATCHDOG_WARNING);
+    }
+    $result = array();
+    foreach ($entity_ids as $id) {
+      $result[$id] = FALSE;
+    }
+
+    return $result;
+  }
+
+  // Filter out entity_ids that are not integers.
+  $entity_ids = array_filter($entity_ids, 'is_numeric');
+  // If everything was filtered out, return an empty array.
+  if (empty($entity_ids)) {
+    return array();
+  }
+  $sql = "SELECT entity_id, pathauto FROM {pathauto_persist} WHERE entity_type = :entity_type AND entity_id IN (:entity_ids)";
+  $pathauto_state = db_query($sql, array(':entity_type' => $entity_type, ':entity_ids' => $entity_ids))->fetchAllKeyed();
+
   return $pathauto_state;
 }
 
@@ -89,4 +137,5 @@ function pathauto_persist_entity_state_save($entity_type, $entity, $pathauto_sta
       'pathauto' => $pathauto_state ? 1 : 0,
     ))
     ->execute();
+  drupal_static_reset('pathauto_persist_entity_load');
 }
