fixed reconnection logic