diff --git a/manualcrop.helpers.inc b/manualcrop.helpers.inc
index cb71e28..d04cc7b 100644
--- a/manualcrop.helpers.inc
+++ b/manualcrop.helpers.inc
@@ -720,37 +720,24 @@ function manualcrop_save_crop_data($file, $data) {
  *   - "height": An integer representing the height in pixels.
  */
 function manualcrop_load_crop_selection($file, $style_name = NULL) {
-  // Choose which table to use based on whether or not file_entity_revisions module is enabled.
+
+  $query = db_select('manualcrop', 'mc');
   if (module_exists('file_entity_revisions')) {
-    $table = 'file_managed_revisions';
-    $key = 'vid';
+    $query->join('file_managed', 'f', 'mc.vid = f.vid');
+    $query->join('file_managed_revisions', 'r', 'f.vid = r.vid AND r.uri = :uri', array(':uri' => $file));
   }
   else {
-    $table = 'file_managed';
-    $key = 'fid';
+    $query->join('file_managed', 'f', 'mc.fid = f.fid');
+    $query->condition('f.uri', $file);
   }
-
   if (isset($style_name)) {
-    // The fetchObject() call below will use the first result found by this
-    // query, so order it by file revision ID descending to use the most recent
-    // manual crop settings associated with the provided file URI.
-    $result = db_query('SELECT c.x, c.y, c.width, c.height FROM {manualcrop} c INNER JOIN {' . $table . '} f ON c.' . $key . ' = f.' . $key . ' WHERE c.style_name = :name AND f.uri = :uri ORDER BY c.vid DESC', array(
-      ':name' => $style_name,
-      ':uri' => $file,
-    ));
-
-    return $result->fetchObject();
+    $query->fields('mc', array('x', 'y', 'width', 'height', 'style_name'));
+    $query->condition('mc.style_name', $style_name);
+    return $query->execute()->fetchObject();
   }
   else {
-    // The fetchAllAssoc() call below will use the last result found by this
-    // query for each style name, so order it by file revision ID ascending
-    // to use the most recent manual crop settings associated with the provided
-    // file URL for each style.
-    $result = db_query('SELECT c.style_name, c.x, c.y, c.width, c.height FROM {manualcrop} c INNER JOIN {' . $table . '} f ON c.' . $key . ' = f.' . $key . ' WHERE f.uri = :uri ORDER BY c.vid', array(
-      ':uri' => $file,
-    ));
-
-    return $result->fetchAllAssoc('style_name');
+    $query->fields('mc', array('x', 'y', 'width', 'height'));
+    return $query->execute()->fetchAllAssoc('style_name');
   }
 }
 
diff --git a/manualcrop.install b/manualcrop.install
index 71a2ec1..514659a 100644
--- a/manualcrop.install
+++ b/manualcrop.install
@@ -131,6 +131,9 @@ function manualcrop_schema() {
       ),
     ),
     'primary key' => array('fid', 'vid', 'style_name'),
+    'indexes' => array(
+      'vid' => array('vid'),
+    ),
   );
 
   return $schema;
@@ -445,6 +448,13 @@ function manualcrop_update_7109() {
 }
 
 /**
+ * Add index on vid.
+ */
+function manualcrop_update_7110() {
+  db_add_index('manualcrop', 'vid', array('vid'));
+}
+
+/**
  * Grant the crop permission to all user roles.
  */
 function _manualcrop_grant_crop_permission() {
