added more error checking and a loading image.