Fixed Progress bar  bugs and refined the code.