diff --git a/entityreference_prepopulate.module b/entityreference_prepopulate.module
index 9e47f8c..65f3cc2 100644
--- a/entityreference_prepopulate.module
+++ b/entityreference_prepopulate.module
@@ -257,30 +257,34 @@ function entityreference_prepopulate_get_values_from_url($field, $instance, $fla
     return $cache[$identifier];
   }
 
-  // Check to see if we cached the values in a $form_state object (and we are
-  // refreshing the form)
-  $form_build_id = isset($_GET['form_build_id']) ? $_GET['form_build_id'] : isset($_POST['form_build_id']) ? $_POST['form_build_id'] : NULL;
-  if (!empty($form_build_id)) {
-    $form_state = array();
-    $form = form_get_cache($form_build_id, $form_state);
-    if (isset($form_state['entityreference_prepopulate'][$instance['entity_type']][$instance['bundle']][$field_name])) {
-      $ids = $form_state['entityreference_prepopulate'][$instance['entity_type']][$instance['bundle']][$field_name];
-    }
-  }
-  elseif (empty($_GET[$field_name]) || !is_string($_GET[$field_name]) || empty($instance['settings']['behaviors']['prepopulate']['status'])) {
+  // Do nothing when prepopulate is disabled for this field.
+  if (!$instance['settings']['behaviors']['prepopulate']['status']) {
     $cache[$identifier] = FALSE;
     return;
   }
-  else {
+
+  // Get the value from the URL if possible.
+  if (!empty($_GET[$field_name]) && is_string($_GET[$field_name])) {
     $ids = explode(',', $_GET[$field_name]);
   }
+  else {
+    // Try to get the form out of cache.
+    $form_build_id = isset($_GET['form_build_id']) ? $_GET['form_build_id'] : isset($_POST['form_build_id']) ? $_POST['form_build_id'] : NULL;
+    $form_state = array();
+    $form = form_get_cache($form_build_id, $form_state);
 
-  if (!$ids) {
-    $cache[$identifier] = FALSE;
-    return;
+    // If successful, get the value from the form_state.
+    if (isset($form_state['entityreference_prepopulate'][$instance['entity_type']][$instance['bundle']][$field_name])) {
+      $ids = $form_state['entityreference_prepopulate'][$instance['entity_type']][$instance['bundle']][$field_name];
+    }
+    // If not, do nothing and return.
+    else {
+      $cache[$identifier] = FALSE;
+      return;
+    }
   }
 
-  // Check if the IDs are valid, and get filter out the ones that are not valid.
+  // Check if the IDs are valid, and filter out the invalid ones.
   $handler = entityreference_get_selection_handler($field, $instance);
   if (!$ids = $handler->validateReferencableEntities($ids)) {
     $cache[$identifier] = FALSE;
