Better connection close handling.
Fix build errors