Fix connection reset logic