Improve internet connection detection logic