diff --git a/image_field_random.module b/image_field_random.module
index 7142ec5..3b419a9 100644
--- a/image_field_random.module
+++ b/image_field_random.module
@@ -48,25 +48,19 @@ function image_field_random_form_field_ui_field_edit_form_alter(&$form, &$form_s
 }
 
 /**
- * Implements hook_field_attach_submit().
+ * Implements hook_entity_presave().
  */
-function image_field_random_field_attach_submit($entity_type, $entity, $form, &$form_state) {
+function image_field_random_entity_presave($entity, $type) {
 
-  // First find the image fields. This proces is much more complicated than
-  // it probably should be.
-  // 1. Grab the name of the entity bundle
-  // 2. Grab the list of fields for the given entity type and bundle
-  // 3. Loop through all fields in that type and bundle and get the image
-  //    fields names.
-  $entity_info = entity_get_info($entity_type);
+  $entity_info = entity_get_info($type);
 
   // User entity doesn't have a bundle. So you just pass the type into the
   // bundle field.
   if (empty($entity_info['entity keys']['bundle'])) {
-    $field_instances_info = field_info_instances($entity_type, $entity_type);
+    $field_instances_info = field_info_instances($type, $type);
   }
   else {
-    $field_instances_info = field_info_instances($entity_type, $entity->{$entity_info['entity keys']['bundle']});
+    $field_instances_info = field_info_instances($type, $entity->{$entity_info['entity keys']['bundle']});
   }
 
   $image_fields = array();
@@ -75,16 +69,7 @@ function image_field_random_field_attach_submit($entity_type, $entity, $form, &$
 
     if ($field_info['type'] == 'image') {
       $image_fields[$field_name] = $field_instance_info['settings'];
-      $image_fields[$field_name]['uri_scheme'] = $field_info['settings']['uri_scheme'];      
-
-      // While the data is available find out if the field is empty in this
-      // entity. //ToDo: allow multi-value fields?
-      $empty_function = $field_info['module'] . '_field_is_empty';
-
-      if (function_exists($empty_function)) {
-        $image_fields[$field_name]['empty'] = !isset($form[$field_name]['und'][0]['#value']) ||
-          $empty_function($form[$field_name]['und'][0]['#value'], $field_info);
-      }
+      $image_fields[$field_name]['uri_scheme'] = $field_info['settings']['uri_scheme'];
     }
   }
 
@@ -92,10 +77,10 @@ function image_field_random_field_attach_submit($entity_type, $entity, $form, &$
   // field has random_default set and the image field is empty choose a random
   // file of the supported file type in the directory.
   foreach ($image_fields as $field_name => $field_instance_info) {
-    if ($field_instance_info['random_default'] && $field_instance_info['empty']) {
+    if ($field_instance_info['random_default'] && !isset($entity->{$field_name}['und'][0]) ) {
 
       $files = file_scan_directory(
-        $field_instance_info['uri_scheme'] . '://' . $field_instance_info['random_default_path'], 
+        $field_instance_info['uri_scheme'] . '://' . $field_instance_info['random_default_path'],
         '/^[\w|\s|!|@|#|\$|%|\^|&|\*|\(|\)|-|\+|=|\{|\}|\||\[|\]|"|\'|~|`|\.]*\.(' . implode('|', explode(' ', $field_instance_info['file_extensions'])) . ')$/'
       );
 
@@ -117,11 +102,11 @@ function image_field_random_field_attach_submit($entity_type, $entity, $form, &$
 
       // 2. Check if a file id exists for it
       $result = db_select('file_managed', 'fm')
-              ->fields('fm', array('fid'))
-              ->condition('fm.uri', $file_selection)
-              ->execute()
-              // Fetch as array
-              ->fetchAll(PDO::FETCH_ASSOC);
+        ->fields('fm', array('fid'))
+        ->condition('fm.uri', $file_selection)
+        ->execute()
+        // Fetch as array
+        ->fetchAll(PDO::FETCH_ASSOC);
 
       // 3. If it does not create a new one
       if (empty($result)) {
@@ -132,23 +117,17 @@ function image_field_random_field_attach_submit($entity_type, $entity, $form, &$
         $file->filename = $files[$file_selection]->filename;
         $file->uri = $file_selection;
         $file->filemime = file_get_mimetype($file_selection, $mapping = NULL);
-        $file->status = 1;
+        $file->status = FILE_STATUS_PERMANENT;
 
+        $file = file_copy($file, $field_instance_info['uri_scheme'] . '://' . $field_instance_info['file_directory'], FILE_EXISTS_RENAME);
         file_save($file);
       }
       else {
         $file = file_load($result[0]['fid']);
       }
 
-      // Add a fake file usage to prevent files pulled form the random directory 
-      // from being deleted when they are no longer referenced.
-      $usage = file_usage_list($file);
-      if (!isset($usage['image_field_random'])) {
-        file_usage_add($file, 'image_field_random', 'image_field_random', 0);
-      }
-
       // 4. Identify this file for the field
-      $entity->{$field_name}['und'][0] = (array) $file;
+     $entity->{$field_name}['und'][0] = (array) $file;
     }
   }
-}
+}
\ No newline at end of file
