             let frame = Frame(fin: fin, opCode: code, data: frameData, maskKey: maskKey)
             let data = frame.getData()
             try stream.send(data)
-        }
-        
-        try stream.flush()
+            try stream.flush()
+        }
     }
     
     static func accept(_ key: String) -> String {

    
    private func send(_ opCode: Frame.OpCode, data: Data) throws {
        let maskKey: Data = []
        
        let remainingData = data.count % 64_000
        var frameCount = (data.count - remainingData) / 64_000
        
        if remainingData > 0 {
            frameCount += 1

        for i in 0..<frameCount {
            let code: Frame.OpCode
            
            let start = i*packetSize
            let end = i == frameCount-1 ? start+remainingData : (i+1)*packetSize
            let frameData = Data(data[start..<end])
            
            if opCode == .Text && i != 0 {
