diff --git a/includes/import.inc b/includes/import.inc
index d51ab13..fd60a44 100644
--- a/includes/import.inc
+++ b/includes/import.inc
@@ -69,16 +69,17 @@ function icon_provider_import_form_validate($form, &$form_state) {
   // against the archive file contents.
   $temp_dir = 'temporary://icon_api_' . md5(REQUEST_TIME);
   try {
-    $archive = icon_archive_extract(drupal_realpath($file->uri), drupal_realpath($temp_dir));
+    $archiver = icon_archive_extract(drupal_realpath($file->uri), drupal_realpath($temp_dir));
   }
   catch (Exception $e) {
     form_set_error('file', $e->getMessage());
+    $archiver->getArchive()->close();
     file_delete($file);
     file_unmanaged_delete_recursive($temp_dir);
     return;
   }
   // Set the archive extraction path temporarily as the bundle path.
-  $bundle['path'] = $temp_dir . '/' . $archive->dir;
+  $bundle['path'] = $temp_dir . '/' . $archiver->dir;
   // Automatic detection. Iterate over each provider and find the first one that
   // can import the archive file.
   if (!$provider) {
@@ -96,6 +97,8 @@ function icon_provider_import_form_validate($form, &$form_state) {
       form_set_error('file', t('Unable to automatically detect which provider should be used to import %file. Try manually selecting which provider to use or re-download the archive file from the provider.', array(
         '%file' => $file->filename,
       )));
+      // Close opened archive before trying to delete it.
+      $archiver->getArchive()->close();
       file_delete($file);
       file_unmanaged_delete_recursive($temp_dir);
       return;
@@ -107,6 +110,8 @@ function icon_provider_import_form_validate($form, &$form_state) {
     $validation = icon_extension_invoke($provider['type'], $provider[$provider['type']], 'icon_' . $provider['name'] . '_import_validate', $bundle);
     if ($validation !== TRUE) {
       form_set_error('file', $validation);
+      // Close opened archive before trying to delete it.
+      $archiver->getArchive()->close();
       file_delete($file);
       file_unmanaged_delete_recursive($temp_dir);
       return;
@@ -120,6 +125,8 @@ function icon_provider_import_form_validate($form, &$form_state) {
   if (!$bundle['path'] = icon_file_move_recursive($bundle['path'], 'public://icon/' . $bundle['provider'], $bundle['name'])) {
     form_set_error('file', t('An error occured while attempting to extract the uploaded archive. Check the logs for more details.'));
   }
+  // Close opened archive before trying to delete it.
+  $archiver->getArchive()->close();
   // Delete the uploaded archive file and temporary directory.
   file_delete($file);
   file_unmanaged_delete_recursive($temp_dir);
diff --git a/includes/utilities.inc b/includes/utilities.inc
index 1b53f77..824dfe9 100644
--- a/includes/utilities.inc
+++ b/includes/utilities.inc
@@ -32,6 +32,8 @@ function icon_archive_extract($file, $directory) {
     $archiver->extract($directory);
   }
   catch (Exception $e) {
+    // Close opened archive before trying to delete it.
+    $archiver->getArchive()->close();
     if (file_exists($extract_location)) {
       file_unmanaged_delete_recursive($extract_location);
     }
@@ -268,13 +270,13 @@ function icon_enabled_themes() {
  *    The URI of the moved file or directory, or FALSE in the event of an error.
  */
 function icon_file_move_recursive($source, $destination = NULL, $rename = FALSE, $replace = FILE_EXISTS_REPLACE, $depth = 0) {
-  if (is_dir($source)) {
+  if (is_dir(drupal_realpath($source))) {
     if (!$depth) {
       $destination .= '/' . ($rename ? $rename : drupal_basename($source));
-      file_unmanaged_delete_recursive($destination);
+      file_unmanaged_delete_recursive(drupal_realpath($destination));
     }
     file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
-    $dir = dir($source);
+    $dir = dir(drupal_realpath($source));
     while (($file = $dir->read()) !== FALSE) {
       if ($file == '.' || $file == '..') {
         continue;
@@ -287,12 +289,12 @@ function icon_file_move_recursive($source, $destination = NULL, $rename = FALSE,
       }
     }
     $dir->close();
-    if (!file_unmanaged_delete_recursive($source)) {
+    if (!file_unmanaged_delete_recursive(drupal_realpath($source))) {
       return FALSE;
     }
     return $destination;
   }
-  elseif (is_file($source)) {
+  elseif (is_file(drupal_realpath($source))) {
     return file_unmanaged_copy($source, $destination, $replace);
   }
   return FALSE;
