diff --git a/apachesolr_attachments.index.inc b/apachesolr_attachments.index.inc
index e75a944..c47be79 100644
--- a/apachesolr_attachments.index.inc
+++ b/apachesolr_attachments.index.inc
@@ -186,20 +186,23 @@ function apachesolr_attachments_extract_using_solr($filepath) {
  *
  */
 function apachesolr_attachments_add_file_usage(stdClass $file, $parent_entity_type, $parent_entity_id) {
-  $indexer_table = apachesolr_get_indexer_table('file');
-  db_merge($indexer_table)
-    ->key(array(
-      'entity_type' => 'file',
-      'entity_id' => $file->fid,
-      'parent_entity_type' => $parent_entity_type,
-      'parent_entity_id' => $parent_entity_id,
-    ))
-    ->fields(array(
-      'bundle' => 'file',
-      'status' => 1,
-      'changed' => REQUEST_TIME,
-    ))
-    ->execute();
+  $entity_info = entity_get_info($parent_entity_type);
+  if (!empty($entity_info['apachesolr']['indexable'])) {
+    $indexer_table = apachesolr_get_indexer_table('file');
+    db_merge($indexer_table)
+      ->key(array(
+        'entity_type' => 'file',
+        'entity_id' => $file->fid,
+        'parent_entity_type' => $parent_entity_type,
+        'parent_entity_id' => $parent_entity_id,
+      ))
+      ->fields(array(
+        'bundle' => 'file',
+        'status' => 1,
+        'changed' => REQUEST_TIME,
+      ))
+      ->execute();
+  }
 }
 
 /**
@@ -227,6 +230,13 @@ function apachesolr_attachments_delete_file_usage(stdClass $file, $parent_entity
 function apachesolr_attachments_clean_index_table() {
   $indexer_table = apachesolr_get_indexer_table('file');
   db_delete($indexer_table)
-    ->condition('parent_entity_id', 0)
-    ->execute();
+  ->condition('parent_entity_id', 0)
+  ->execute();
+  foreach (entity_get_info() as $entity_type => $entity_info) {
+    if (empty($entity_info['apachesolr']['indexable'])) {
+      db_delete($indexer_table)
+      ->condition('parent_entity_type', $entity_type)
+      ->execute();
+    }
+  }
 }
\ No newline at end of file
diff --git a/apachesolr_attachments.module b/apachesolr_attachments.module
index 577d9c0..e33e57a 100644
--- a/apachesolr_attachments.module
+++ b/apachesolr_attachments.module
@@ -72,94 +72,93 @@ function apachesolr_attachments_apachesolr_entity_info_alter(&$entity_info) {
 function apachesolr_attachments_solr_document(ApacheSolrDocument $document, $file, $entity_type, $env_id) {
   module_load_include('inc', 'apachesolr_attachments', 'apachesolr_attachments.index');
   $documents = array();
+  $table = apachesolr_get_indexer_table('file');
 
+  // Text is saved in the index table. Will be used by the node indexing if
+  // available.
   $text = apachesolr_attachments_get_attachment_text($file);
   // If we don't have extracted text we should stop our process here
+
   if (empty($text)) {
     return $documents;
   }
-  // Text is saved in the index table. Will be used by the node indexing if
-  // available.
-  // Function should exist that updates the changed data for a node when the
-  // file was updated/extracted
-
-  // Get list of nodes that are linked to this particular file
-  // A single file might be attached to multiple nodes.
-  $parents = file_get_file_references($file, NULL, FIELD_LOAD_CURRENT);
-  $parents_list = $parents ? reset($parents) : NULL;
-  if (!empty($parents_list)) {
-    foreach ($parents_list as $parent_entity_type => $parent) {
-      foreach ($parent as $parent_entity_id => $parent_info) {
-        // load the parent entity and reset cache
-        $parent_entities = entity_load($parent_entity_type, array($parent_entity_id), NULL, TRUE);
-        $parent_entity = reset($parent_entities);
-
-        // Skip invalid entities
-        if (empty($parent_entity)) {
-          continue;
-        }
-
-        // Retrieve the parent entity id and bundle
-        list($parent_entity_id, $parent_entity_vid, $parent_entity_bundle) = entity_extract_ids($parent_entity_type, $parent_entity);
-
-        // Get a clone of the bare minimum document
-        $filedocument = clone $document;
 
-        //Get the callback array to add stuff to the document
-        $callbacks = apachesolr_entity_get_callback($parent_entity_type, 'document callback');
-        // Skip invalid entity types
-        if (empty($callbacks)) {
-          continue;
-        }
+  // Get the list of parents that we should index from the indexing table
+  $parents = db_select($table, 'aie')
+    ->fields('aie')
+    ->condition('entity_type', 'file')
+    ->condition('entity_id', $file->fid)
+    ->execute();
+
+  foreach ($parents as $parent) {
+    // load the parent entity and reset cache
+    $parent_entities = entity_load($parent->parent_entity_type, array($parent->parent_entity_id), NULL, TRUE);
+    $parent_entity = reset($parent_entities);
+
+    // Skip invalid entities
+    if (empty($parent_entity)) {
+      continue;
+    }
 
-        $build_documents = array();
-        foreach ($callbacks as $callback) {
-          // Call a type-specific callback to add stuff to the document.
-          $build_documents = array_merge($build_documents, $callback($filedocument, $parent_entity, $parent_entity_type, $env_id));
-        }
+    // Retrieve the parent entity id and bundle
+    list($parent_entity_id, $parent_entity_vid, $parent_entity_bundle) = entity_extract_ids($parent->parent_entity_type, $parent_entity);
+    $parent_entity_type = $parent->parent_entity_type;
+    // Get a clone of the bare minimum document
+    $filedocument = clone $document;
+
+    //Get the callback array to add stuff to the document
+    $callbacks = apachesolr_entity_get_callback($parent_entity_type, 'document callback');
+    // Skip invalid entity types
+    if (empty($callbacks)) {
+      continue;
+    }
 
-        // Take the top document from the stack
-        $filedocument = reset($build_documents);
-
-        // Build our separate document and overwrite basic information
-        $filedocument->id = apachesolr_document_id($file->fid . '-' . $parent_entity_type . '-' . $parent_entity_id, $entity_type);
-        $filedocument->url = file_create_url($file->uri);
-        $filedocument->path = file_stream_wrapper_get_instance_by_uri($file->uri)->getExternalUrl();
-
-        // Add extra info to our document
-        $filedocument->label = apachesolr_clean_text($file->filename);
-        $filedocument->content = apachesolr_clean_text($file->filename) . ' ' . $text;
-
-        $filedocument->ds_created = apachesolr_date_iso($file->timestamp);
-        $filedocument->ds_changed = $filedocument->ds_created;
-
-        $filedocument->created = apachesolr_date_iso($file->timestamp);
-        $filedocument->changed = $filedocument->created;
-
-        // Add Parent information fields. See http://drupal.org/node/1515822 for explanation
-        $parent_entity_info = entity_get_info($parent_entity_type);
-        $small_parent_entity = new stdClass();
-        $small_parent_entity->entity_type = $parent_entity_type;
-        $small_parent_entity->{$parent_entity_info['entity keys']['id']} = $parent_entity_id;
-        $small_parent_entity->{$parent_entity_info['entity keys']['bundle']} = $parent_entity_bundle;
-        $small_parent_entity->{$parent_entity_info['entity keys']['label']} = $parent_entity->{$parent_entity_info['entity keys']['label']};
-
-        // Add all to one field because if it is spread out over
-        // multiple fields there is no way of knowing which multifield value
-        // belongs to which entity
-        // It does not load the complete entity in to the index because that
-        // would dramatically increase the index size and processing time
-        $filedocument->zm_parent_entity = drupal_json_encode($small_parent_entity);
-        $filedocument->sm_parent_entity_bundle = $parent_entity_type . "-" . $parent_entity_bundle;
-        $filedocument->sm_parent_entity_type = $parent_entity_type;
-
-        // Add Apachesolr Attachments specific fields.
-        $filedocument->ss_filemime = $file->filemime;
-        $filedocument->ss_filesize = $file->filesize;
-
-        $documents[] = $filedocument;
-      }
+    $build_documents = array();
+    foreach ($callbacks as $callback) {
+      // Call a type-specific callback to add stuff to the document.
+      $build_documents = array_merge($build_documents, $callback($filedocument, $parent_entity, $parent_entity_type, $env_id));
     }
+
+    // Take the top document from the stack
+    $filedocument = reset($build_documents);
+
+    // Build our separate document and overwrite basic information
+    $filedocument->id = apachesolr_document_id($file->fid . '-' . $parent_entity_type . '-' . $parent_entity_id, $entity_type);
+    $filedocument->url = file_create_url($file->uri);
+    $filedocument->path = file_stream_wrapper_get_instance_by_uri($file->uri)->getExternalUrl();
+
+    // Add extra info to our document
+    $filedocument->label = apachesolr_clean_text($file->filename);
+    $filedocument->content = apachesolr_clean_text($file->filename) . ' ' . $text;
+
+    $filedocument->ds_created = apachesolr_date_iso($file->timestamp);
+    $filedocument->ds_changed = $filedocument->ds_created;
+
+    $filedocument->created = apachesolr_date_iso($file->timestamp);
+    $filedocument->changed = $filedocument->created;
+
+    // Add Parent information fields. See http://drupal.org/node/1515822 for explanation
+    $parent_entity_info = entity_get_info($parent_entity_type);
+    $small_parent_entity = new stdClass();
+    $small_parent_entity->entity_type = $parent_entity_type;
+    $small_parent_entity->{$parent_entity_info['entity keys']['id']} = $parent_entity_id;
+    $small_parent_entity->{$parent_entity_info['entity keys']['bundle']} = $parent_entity_bundle;
+    $small_parent_entity->{$parent_entity_info['entity keys']['label']} = $parent_entity->{$parent_entity_info['entity keys']['label']};
+
+    // Add all to one field because if it is spread out over
+    // multiple fields there is no way of knowing which multifield value
+    // belongs to which entity
+    // It does not load the complete entity in to the index because that
+    // would dramatically increase the index size and processing time
+    $filedocument->zm_parent_entity = drupal_json_encode($small_parent_entity);
+    $filedocument->sm_parent_entity_bundle = $parent_entity_type . "-" . $parent_entity_bundle;
+    $filedocument->sm_parent_entity_type = $parent_entity_type;
+
+    // Add Apachesolr Attachments specific fields.
+    $filedocument->ss_filemime = $file->filemime;
+    $filedocument->ss_filesize = $file->filesize;
+
+    $documents[] = $filedocument;
   }
   return $documents;
 }
@@ -214,6 +213,10 @@ function _apachesolr_attachments_get_all_files() {
   foreach ($fields as $field_id => $field_info) {
     if ($field_info['type'] == 'file') {
       foreach ($field_info['bundles'] as $entity_type => $bundles) {
+        $entity_info = entity_get_info($entity_type);
+        if (empty($entity_info['apachesolr']['indexable'])) {
+          continue;
+        }
         $query = new ApachesolrAttachmentsEntityFieldQuery();
         $results_query = $query
           ->entityCondition('entity_type', $entity_type)
@@ -222,13 +225,24 @@ function _apachesolr_attachments_get_all_files() {
           ->addMetaData('field_fid_key', $field_info['field_name'] . '_fid')
           ->execute();
         $results = array_merge_recursive($results, $results_query);
+
       }
     }
   }
   return $results;
 }
 
+function _apachesolr_attachments_get_all_bundles() {
+  // Get all bundles, regardless of the environment
+  $bundles  = db_query("SELECT bundle FROM {apachesolr_index_bundles} WHERE entity_type = :entity_type", array(
+    ':entity_type' => $entity_type,
+  ))->fetchCol();
+  return $bundles;
+}
+
 /*
+ * Implements hook_query_TAG_alter().
+ *
  * Add our file id to the result set
  */
 function apachesolr_attachments_query_apachesolr_attachments_solr_reindex_alter(QueryAlterableInterface $query) {
@@ -239,43 +253,70 @@ function apachesolr_attachments_query_apachesolr_attachments_solr_reindex_alter(
 }
 
 /**
- * Status callback for the files. Optimized so it has a quick return
- * when available
+ * Status callback for the files. Files should never be removed from the table.
+ * See apachesolr_attachments_apachesolr_exclude() for exclusion of items
  * @param type $entity_id
  * @param type $entity_type
  * @return type
  */
 function apachesolr_attachments_status_callback($entity_id, $entity_type) {
   module_load_include('inc', 'apachesolr_attachments', 'apachesolr_attachments.index');
-  // Make sure we have a boolean value.
-  // Anything different from 1 becomes zero
-  if (!$entity_id) {
-    return FALSE;
-  }
-  // Check if the parent entity was not excluded
-  if (apachesolr_attachments_excluded_entities($entity_id, $entity_type) == FALSE) {
-    return FALSE;
-  }
-
   // load the entity and reset cache
   $entities = entity_load($entity_type, array($entity_id), NULL, TRUE);
   $entity = reset($entities);
 
   // Check if the mimetype is allowed
   if (apachesolr_attachments_allowed_mime($entity->filemime) == FALSE) {
+    // Set status to 0 and remove from the index
     return FALSE;
   }
-  // Check if the entity status is active and if it is a real file
-  if ($entity->status != 1) {
+  // Check if the file is a real file
+  if (apachesolr_attachments_is_file($entity) == FALSE) {
+    // Set status to 0 and remove from the index
     return FALSE;
   }
-  if (apachesolr_attachments_is_file($entity) == FALSE) {
+  // Check if the entity status is active
+  if ($entity->status != 1) {
+    // Set status to 0 and remove from the index
     return FALSE;
   }
-
+  // Keep status at 1
   return TRUE;
 }
 
+/**
+ * Implenents hook_apachesolr_ENTITY_TYPE_exclude().
+ *
+ * This is invoked for each file entity that is being inspected to be added to the
+ * index. if any module returns TRUE, the entity is skipped for indexing.
+ *
+ * @param integer $entity_id
+ * @param string $entity_type
+ * @param integer $row
+ *   A complete set of data from the indexing table.
+ * @param string $env_id
+ * @return boolean
+ */
+function apachesolr_attachments_apachesolr_file_exclude($entity_id, $row, $env_id) {
+  module_load_include('inc', 'apachesolr_attachments', 'apachesolr_attachments.index');
+  // Make sure we have a boolean value.
+  // Anything different from 1 becomes zero
+  if (!$entity_id || !$row->parent_entity_id) {
+    // Exclude
+    return TRUE;
+  }
+  // Check if the parent entity is excluded
+  $parent_entity_id = $row->parent_entity_id;
+  $parent_entity_type = $row->parent_entity_type;
+  $exclude = apachesolr_attachments_is_parent_excluded($entity_id, $entity_type, $parent_entity_id, $parent_entity_type, $env_id);
+  if ($exclude) {
+    // Exclude
+    return TRUE;
+  }
+  // Do not exclude
+  return FALSE;
+}
+
 function apachesolr_attachments_is_file($entity) {
   if (!empty($entity->uri)) {
     $filepath = drupal_realpath($entity->uri);
@@ -295,61 +336,56 @@ function apachesolr_attachments_is_file($entity) {
 }
 
 /**
- * Get a list of entities that are linked to this particular file
- * A single file might be attached to multiple entities.
- * Excludes a file as soon as 1 entity was excluded
+ * Excludes a file if the parent_entity is set to status 0 or it is not
+ * being indexed
  * @param type $entity_id
  * @param type $entity_type
  * @return type
  */
-function apachesolr_attachments_excluded_entities($entity_id, $entity_type) {
-  $env_id = apachesolr_default_environment();
-  $status = FALSE;
-
-  $file = file_load($entity_id);
-  // We can't do anything with a faulty file
-  if (empty($file)) {
-    return $status;
+function apachesolr_attachments_is_parent_excluded($entity_id, $entity_type, $parent_entity_id, $parent_entity_type, $env_id) {
+  $query = new EntityFieldQuery();
+  $result = $query
+    ->entityCondition('entity_type', $parent_entity_type)
+    ->entityCondition('entity_id', $parent_entity_id)
+    ->execute();
+  // We only need the class and 1 item;
+  if (empty($result)) {
+    // Parent entity id does not exist anymore
+    return TRUE;
+  }
+  $result = reset(reset($result));
+  $parent_entity_bundle = $result->type;
+  // Ignore this parent if the bundles to be indexed for this entity type
+  // are not indexed
+  $bundles = apachesolr_get_index_bundles($env_id, $parent_entity_type);
+  if (empty($bundles)) {
+    // Exclude it
+    return TRUE;
+  }
+  else if (!in_array($parent_entity_bundle, $bundles)) {
+    // Exclude it
+    return TRUE;
   }
-  $parents = file_get_file_references($file, NULL, FIELD_LOAD_CURRENT);
-  $parents_list = $parents ? reset($parents) : NULL;
-
-  if (!empty($parents_list)) {
-    foreach ($parents_list as $parent_entity_type => $parent) {
-      foreach ($parent as $parent_entity_id => $parent_info) {
-
-        $bundles = apachesolr_get_index_bundles($env_id, $parent_entity_type);
-        // Ignore this parent if the bundles to be indexed for this entity type
-        // are not indexed
-        if (empty($bundles)) {
-          continue;
-        }
-        else if (!in_array($parent_info->type, $bundles)) {
-          continue;
-        }
 
-        // Skip indexing of files if the node was excluded by apache solr
-        $status_callbacks = apachesolr_entity_get_callback($parent_entity_type, 'status callback');
-        if (!empty($status_callbacks)) {
-          // Set status to true. Allow the callbacks to make the change
-          $status = TRUE;
-          // Check status callback before sending to the index
-          foreach ($status_callbacks as $status_callback) {
-            if (is_callable($status_callback)) {
-              // by placing $status in front we prevent calling any other callback
-              // after one status callback returned false
-              $status = $status && $status_callback($parent_entity_id, $parent_entity_type);
-            }
-          }
-        }
+  // Skip indexing of files if the node was excluded by apache solr
+  $status_callbacks = apachesolr_entity_get_callback($parent_entity_type, 'status callback');
+  if (!empty($status_callbacks)) {
+    // Set status to true. Allow the callbacks to make the change
+    $status = TRUE;
+    // Check status callback before sending to the index
+    foreach ($status_callbacks as $status_callback) {
+      if (is_callable($status_callback)) {
+        // by placing $status in front we prevent calling any other callback
+        // after one status callback returned false
+        $status = $status && $status_callback($parent_entity_id, $parent_entity_type);
       }
     }
+    // TRUE means the status is ok. We should return FALSE so it does
+    // not exclude
+    return !$status;
   }
-  // Delete the entity from our index if the status callback returns 0
-  if ($status == FALSE) {
-    apachesolr_remove_entity($env_id, $entity_type, $entity_id);
-  }
-  return $status;
+  // Exclude by default
+  return TRUE;
 }
 
 /**
@@ -540,8 +576,6 @@ function apachesolr_attachments_default_excluded() {
   return $default;
 }
 
-
-
 class ApachesolrAttachmentsEntityFieldQuery extends EntityFieldQuery {
  /**
   * Finishes the query.
