added connection close error handling