Recoded the Progress bar algorithm