implemented reconnect logic