Added changes that checks for internet connection before attempting to
connect