Implement write buffer, rewrite disconnect/error handling code