Changed code to detect on internet loss