Fixing connection close issues