 
         //read in chunks
         var index = dataUnitSize
-        while(index < data.count)
+        var startIndex = 0
+        
+        while(startIndex + index < data.count)
         {
             //try to read 0..<index from the data as String
             //if it is not enough, we will increment the chunk size
-            while(index < data.count)
+            while(startIndex + index < data.count)
             {
-                let chunk = data[0 ..< index]
+                let chunk = data[startIndex ..< startIndex + index]
                 if let  string = String(bytes: chunk, encoding: encoding),
                         string.characters.count > 0
                 {

                    //append it to resul
                    result.append(string)
                    
                    //remove the chunk from data
                    data.removeSubrange(0..<index)
                    
                    //reset index position
                    index = dataUnitSize
                    break
                }
                index += dataUnitSize
            }
        }
        
        if(result == "" && data.count > MINIMUM_BUFFER_SIZE) {
            //could not find any string in the data
            throw Exception.InvalidDataEncoding(requestedEncoding: encoding, description: description)

    let bufferSize:             Int
    let dataUnitSize:           Int

    var data:                   Data
    var buffer:                 [UInt8]
    var encoding:               String.Encoding
    var firstData:              Bool
