loadURLdata function with error checking