updated code for internet connection check and retry attempts