implemented reconnect functionality