RAZ-1880: Refactored code for adding files in order to avoid race conditions on subsequent API calls