Fix reconnection logic in the client