isconnected function updated, disconnect function created