         return (event["id"], event["event"], event["data"])
     }
 
+    private func parseKeyValuePair(line: String) -> (NSString?, NSString?) {
+        var key: NSString?, value: NSString?
+        let scanner = NSScanner(string: line)
+        scanner.scanUpToString(":", intoString: &key)
+        scanner.scanString(":", intoString: nil)
+
+        for newline in validNewlineCharacters {
+            if scanner.scanUpToString(newline, intoString: &value) {
+                break
+            }
+        }
+
+        return (key, value)
+    }
+
     private func parseRetryTime(eventString: String) -> Int? {
         var reconnectTime: Int?
         let separators = NSCharacterSet(charactersInString: ":")


        for line in eventString.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet()) as [String] {
            autoreleasepool {
                var key: NSString?, value: NSString?
                let scanner = NSScanner(string: line)
                scanner.scanUpToString(":", intoString: &key)
                scanner.scanString(":", intoString: nil)
                scanner.scanUpToString("\n", intoString: &value)

                if key != nil && value != nil {
                    if event[key as! String] != nil {

            // Search for next occurrence of delimiter
            searchRange.location = foundRange.location + foundRange.length
            searchRange.length = receivedDataBuffer.length - searchRange.location
        }

        // Remove the found events from the buffer
        self.receivedDataBuffer.replaceBytesInRange(NSRange(location: 0, length: searchRange.location), withBytes: nil, length: 0)

        return events
    }

    private func searchForEventInRange(searchRange: NSRange) -> NSRange? {
        let delimiters = validNewlineCharacters.map { "\($0)\($0)".dataUsingEncoding(NSUTF8StringEncoding)! }

        for delimiter in delimiters {
            let foundRange = receivedDataBuffer.rangeOfData(delimiter,
                                                            options: NSDataSearchOptions(),
                                                            range: searchRange)
            if foundRange.location != NSNotFound {
                return foundRange
            }
        }

        return nil
    }

    private func parseEventStream(events: [String]) {
