diff --git a/.gitignore b/.gitignore
index 3af0ccb687b45753a5c8b3c917d0ebe7cc4ab466..47fb2ace44f326514cb7176a38be8f470b0c5bbc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
 /data
+*.pyc
+**/__pycache__
\ No newline at end of file
diff --git a/preprocessor/preprocessor/archive.py b/preprocessor/preprocessor/archive.py
index 893dc950cf1da9ddd5bf8b52a7c248404e9c5697..7dedcd5f4a040384a2d224c65a6573c763fed3ff 100644
--- a/preprocessor/preprocessor/archive.py
+++ b/preprocessor/preprocessor/archive.py
@@ -1,5 +1,6 @@
 from os import PathLike
 import os.path
+import io
 from typing import List, Union, BinaryIO
 import tarfile
 import zipfile
@@ -35,12 +36,12 @@ def is_tarfile(archive_file: Union[PathLike, BinaryIO]) -> bool:
 def open_tarfile(archive_file: Union[PathLike, BinaryIO]) -> tarfile.TarFile:
     """ Open a TAR file from either a path or a file object.
     """
-    if isinstance(archive_file, BinaryIO):
+    if isinstance(archive_file, (BinaryIO, io.BufferedReader)):
         return tarfile.open(fileobj=archive_file)
     return tarfile.open(archive_file)
 
 
-def unpack_files(archive_path: Union[PathLike, BinaryIO] , target_dir: PathLike, glob=None, filenames=None, recursive=False) -> List[PathLike]:
+def unpack_files(archive_path: Union[PathLike, BinaryIO], target_dir: PathLike, glob=None, filenames=None, recursive=False) -> List[PathLike]:
     """ Unpacks the contents of the specified ZIP or TAR archive to the
         given target directory. Optionally, only a given list of filenames
         will be extracted.
@@ -49,6 +50,7 @@ def unpack_files(archive_path: Union[PathLike, BinaryIO] , target_dir: PathLike,
     """
     iszip = False
     istar = False
+
     # open the archive and extract a list of filenames
     if is_tarfile(archive_path):
         archive = open_tarfile(archive_path)
@@ -94,21 +96,27 @@ def unpack_files(archive_path: Union[PathLike, BinaryIO] , target_dir: PathLike,
         for extension in ARCHIVE_EXTENSIONS:
             sub_archives = filter_filenames(all_filenames, '*.%s' % extension)
             for sub_archive in sub_archives:
+                sub_archive_filename = os.path.join(
+                    os.path.dirname(archive_path),
+                    os.path.basename(sub_archive),
+                )
                 if istar:
-                    sub_archive_file = archive.extractfile(
+                    archive.extract(
                         archive.getmember(sub_archive)
                     )
+                    os.rename(sub_archive, sub_archive_filename)
                 if iszip:
-                    sub_archive_file = archive.open(sub_archive)
+                    archive.extract(sub_archive)
+                    os.rename(sub_archive, sub_archive_filename)
 
                 sub_filenames = unpack_files(
-                    sub_archive_file,
+                    sub_archive_filename,
                     os.path.join(target_dir, sub_archive),
                     glob,
                     filenames,
-                    recursive
+                    recursive,
                 )
                 extracted_filenames.extend(sub_filenames)
 
     # return a list of files extracted
-    return extracted_filenames
\ No newline at end of file
+    return extracted_filenames
diff --git a/preprocessor/preprocessor/util.py b/preprocessor/preprocessor/util.py
index ebc6a6edab872800b9d29ed8fd54f5fced60aa31..9d75850e6ccb4241208f1616a9370e1989506928 100644
--- a/preprocessor/preprocessor/util.py
+++ b/preprocessor/preprocessor/util.py
@@ -2,5 +2,5 @@ import os
 from os.path import splitext
 
 
-def replace_ext(filename: os.PathLike, new_ext: str) -> os.PathLike:
-    return splitext(filename)[0] + ('' if new_ext.startswith('.') else '.') + new_ext
+def replace_ext(filename: os.PathLike, new_ext: str, force_dot: bool=True) -> os.PathLike:
+    return splitext(filename)[0] + ('' if new_ext.startswith('.') or not force_dot else '.') + new_ext