Moved progress bar into a more generic function