 
     processPDF = (finalCallback) -> (pdf) ->
       counter = pdf.numPages
-      finalError = null
-
       for pageNumber in [1..pdf.numPages]
-        if finalError
-          # We call finalCallback only after all pages have been processed and thus callbacks called
-          counter--
-          finalCallback finalError if counter == 0
-          return
-
         pdf.getPage(pageNumber).then (page) ->
-          if finalError
-            # We call finalCallback only after all pages have been processed and thus callbacks called
-            counter--
-            finalCallback finalError if counter == 0
-            return
-
           # pageNumber is not necessary current page number once promise is resolved, use page.pageNumber instead
           progressCallback (page.pageNumber - 1) / pdf.numPages
 

            page.render(renderContext).then ->
              return # Do nothing
            , (error) ->
              finalError = error: "PDF Error page #{ page.pageNumber }", message: error

              # We call finalCallback only after all pages have been processed and thus callbacks called
              counter--
              finalCallback finalError if counter == 0

        pdf.getMetadata(pageNumber).then (metadata) ->
          # TODO: If we will process metadata, too, we have to make sure finalCallback is called after only once after everything is finished

                counter--
                if counter == 0
                  progressCallback 1.0
                  finalCallback()

              appendText: (geom) ->
                width = geom.canvasWidth * geom.hScale
