Improve logic for displaying progressDialog