     /// Socket for the ServerResponse
     ///
     private var socket: Socket?
-    
+
+    ///
+    /// Size of buffer
+    ///
+    private let BUFFER_SIZE = 2000
+
+    ///
+    /// Buffer for HTTP response line, headers, and short bodies
+    ///
+    private var buffer: NSMutableData
+
+    ///
+    /// Whether or not the HTTP response line and headers have been flushed.
+    ///
+    private var startFlushed = false
+
     ///
     /// TODO: ???
     ///
-    private var startFlushed = false
-    
+    private var singleHeaders: [String: String] = [:]
+
     ///
     /// TODO: ???
     ///
-    private var singleHeaders: [String: String] = [:]
-    
-    ///
-    /// TODO: ???
-    ///
     private var multiHeaders: [String: [String]] = [:]
-    
+
     ///
     /// Status code
     ///
     private var status = HttpStatusCode.OK.rawValue
-    
+
     ///
     /// Status code
     ///

    public func end() throws {
        if  let socket = socket {
            try flushStart()
            socket.close()
        }
        socket = nil
    }
    
    ///
    /// Begin flushing the buffer
    ///

    ///
    private func flushStart() throws {

        if  socket == nil  ||  startFlushed  {
            return
        }

        try writeToSocketThroughBuffer(text: "HTTP/1.1 ")
        try writeToSocketThroughBuffer(text: String(status))
        try writeToSocketThroughBuffer(text: " ")
        var statusText = Http.statusCodes[status]

        if  statusText == nil {
            statusText = ""
        }

        try writeToSocketThroughBuffer(text: statusText!)
        try writeToSocketThroughBuffer(text: "\r\n")

        for (key, value) in singleHeaders {
            try writeToSocketThroughBuffer(text: key)
            try writeToSocketThroughBuffer(text: ": ")
            try writeToSocketThroughBuffer(text: value)
            try writeToSocketThroughBuffer(text: "\r\n")
        }

        for (key, valueSet) in multiHeaders {
            for value in valueSet {
                try writeToSocketThroughBuffer(text: key)
                try writeToSocketThroughBuffer(text: ": ")
                try writeToSocketThroughBuffer(text: value)
                try writeToSocketThroughBuffer(text: "\r\n")
            }
        }

        try writeToSocketThroughBuffer(text: "\r\n")
        startFlushed = true
    }

    ///
    /// Function to write Strings to the socket through the buffer
    ///
    private func writeToSocketThroughBuffer(text: String) throws {
        guard let socket = socket,
              let utf8Data = StringUtils.toUtf8String(text) else {
            return
        }

        if  buffer.length + utf8Data.length > BUFFER_SIZE  &&  buffer.length != 0  {
            try socket.write(from: buffer)
            buffer.length = 0
        }
        if  utf8Data.length > BUFFER_SIZE {
            try socket.write(from: utf8Data)
        }
        else {
            buffer.append(utf8Data)
        }
    }
}
