isConnected function updated