fix reconnection logic