improve connection tracking and reconnect logic