Improved progress bar code, thanks @soberstadt!