 
 }
 
-private class CSVKeyedDecodingContainer<K: CodingKey> : KeyedDecodingContainerProtocol {
+fileprivate final class CSVKeyedDecodingContainer<K: CodingKey>: KeyedDecodingContainerProtocol {
 
     typealias Key = K
 
     private let decoder: _CSVRowDecoder
-        var codingPath: [CodingKey] {
+
+    public var codingPath: [CodingKey] {
         return self.decoder.codingPath
     }
 
     public var allKeys: [Key] {
-        guard let headerRow = decoder.reader.headerRow else {
-            return []
-        }
+        guard let headerRow = self.decoder.reader.headerRow else { return [] }
         return headerRow.compactMap { Key(stringValue: $0) }
     }
 
-    init(referencing decoder: _CSVRowDecoder) {
+    fileprivate init(referencing decoder: _CSVRowDecoder) {
         self.decoder = decoder
     }
 
-    private func value(for codingKey: CodingKey) -> String? {
-        var value: String?
-
-        if let index = codingKey.intValue {
-            value = decoder.reader[index]
+    private func value(for key: Key) -> String? {
+        guard self.contains(key) else { return nil }
+
+        if let index = key.intValue {
+            return self.decoder.reader.currentRow![index]
         } else {
-            if decoder.reader.headerRow != nil {
-                value = decoder.reader[codingKey.stringValue]
-            }
-        }
-        return value
+            return self.decoder.reader[key.stringValue]
+        }
     }
 
     private func _errorDescription(of key: CodingKey) -> String {

        self.decoder.codingPath.append(key)
        defer { self.decoder.codingPath.removeLast() }

        guard let result = try decoder.unbox(field, as: UInt.self) else {
            throw DecodingError.valueNotFound(type, DecodingError.Context(codingPath: self.decoder.codingPath, debugDescription: "Expected \(type) value but found null instead."))
        }
        return result

        self.decoder.codingPath.append(key)
        defer { self.decoder.codingPath.removeLast() }

        guard let result = try self.decoder.unbox(field, as: Int.self) else {
            throw DecodingError.valueNotFound(type, DecodingError.Context(codingPath: self.decoder.codingPath, debugDescription: "Expected \(type) value but found null instead."))
        }
        return result
