Progress bar not working correctly