I would abstract the progress bar management in a separate function