 
   return unless importingFilesCount
 
-  finishedFilesCount = ImportingFile.documents.find(state: $in: ['finished', 'imported']).count()
+  finishedImportedFilesCount = ImportingFile.documents.find(state: $in: ['finished', 'imported']).count()
 
   # If there are any files still in progress or if there are any errors, do nothing
-  return if importingFilesCount isnt finishedFilesCount
+  return if importingFilesCount isnt finishedImportedFilesCount
 
   importedFilesCount = ImportingFile.documents.find(state: 'imported').count()
 

# Process next element from import queue
Deps.autorun ->
  # Autorun will not re-run when document changes status from 'preprocessed' to 'importing',
  # but after it changes to any other status, next file will be returned.
  document = ImportingFile.documents.findOne
    state:
      $in: ['importing', 'preprocessed']


hideOverlay = ->
  allCount = ImportingFile.documents.find().count()
  erroredFinishedImportedCount = ImportingFile.documents.find(
    state:
      $in: ['errored', 'finished', 'imported']
  ).count()

  # We prevent hiding if user is uploading files
  if allCount is erroredFinishedImportedCount
    Session.set 'importOverlayActive', false
    ImportingFile.documents.remove {}

