     # Make sure our list of files is an array, even if it's only one file
     if not Array.isArray(referenceFiles)
       referenceFiles = [referenceFiles]
+
     try
       references = []
+
       for file in referenceFiles
-
         # What type of file is this?
-        ftype = file.split('.')
-        ftype = ftype[ftype.length - 1]
+        fileType = file.split('.').pop()
 
         if fs.statSync(file).isFile()
-          if ftype is "json"
-            cpobject = JSON.parse fs.readFileSync(file, 'utf-8')
-            citeproc_refs = citeproc.parse cpobject
-            references = references.concat citeproc_refs
-
-          else if ftype is "yaml"
-            cpobject = yaml.load fs.readFileSync(file, 'utf-8')
-            citeproc_refs = citeproc.parse cpobject
-            references = references.concat citeproc_refs
-
+          if fileType is "json"
+            citeprocObject = JSON.parse fs.readFileSync(file, 'utf-8')
+            citeprocReferences = citeproc.parse citeprocObject
+            references = references.concat citeprocReferences
+          else if fileType is "yaml"
+            citeprocObject = yaml.load fs.readFileSync(file, 'utf-8')
+            citeprocReferences = citeproc.parse citeprocObject
+            references = references.concat citeprocReferences
           else
             # Default to trying to parse as a BibTeX file.
-            parser = new bibtexParse(fs.readFileSync(file, 'utf-8'))
-            references = references.concat @parseBibtexAuthors parser.parse()
-
+            bibtexParser = new bibtexParse fs.readFileSync(file, 'utf-8')
+            references = references.concat @parseBibtexAuthors bibtexParser.parse()
+
+          @bibtex = references
         else
           console.warn("'#{file}' does not appear to be a file, so autocomplete-bibtex will not try to parse it.")
-
-      @bibtex = references
     catch error
       console.error error
 
   prettifyTitle: (title) ->
     return if not title
+
     # Mendeley wraps title with double {{}}, while the parser
     # only removes one set of those. remove the second set here
-    title = title.replace(/^\{/, "")
-    title = title.replace(/\}$/, "")
-    title = titlecaps(title)
-    return title
+    titlecaps(title.replace(/(^\{|\}$)/g, ""))
 
   parseBibtexAuthors: (citations) ->
     for citation in citations

        # Match the regex to the line, and return the match
        line.match(regex)?[0] or ''


  serialize: -> {
    deserializer: 'ReferenceProvider'
    data: { bibtex: @bibtex, possibleWords: @possibleWords }

    else
      @buildWordListFromFiles(atom.config.get "autocomplete-bibtex.bibtex")

    if @bibtex.length == 0
      @buildWordListFromFiles(atom.config.get "autocomplete-bibtex.bibtex")

