Connection reset fix

Better handling if a connection is reset.