Fixes issue where process was ended too early

`processedHits` is counted up in the global scope before they are actually being processed. After they are processed `processedHits` is used to check if all hits have been stored. 

The issue here is, that `processedHits` can already be equal to `totalHits` even though the last request hasn't finished successfully. And since that causes the process to exit, the running request is cancelled and the last hits are lost.