Update the loading code to accurately show and hide the indicator