updated reconnect code