                 throw WMFKeychainCredentialsError.unexpectedData
         }
         return value
+    }
+    
+    private func query(forKey key: String) -> Dictionary<String, AnyObject> {
+        var query = commonConfigurationDictionary(forKey: key)
+        query[kSecMatchLimit as String] = kSecMatchLimitOne
+        query[kSecReturnData as String] = kCFBooleanTrue
+        return query
     }
     
     fileprivate func deleteValue(forKey key:String) throws {

        return value
    }
    
    private func setNewUUID(forKey key: String) {
        trySet(UUID().uuidString, forKey: key)
    }
    
    private func trySet(_ newValue: Any?, forKey key: String) {
        do {
            return try set(value: newValue, forKey: key)
        } catch  {
            assertionFailure("\(error)")
        }
    }
    
    fileprivate enum WMFKeychainCredentialsError: Error {
        case noValue
        case unexpectedData
        case couldNotDeleteData
        case unhandledError(status: OSStatus)
    }
    
    fileprivate func commonConfigurationDictionary(forKey key:String) -> [String : AnyObject] {
        return [
            kSecClass as String : kSecClassGenericPassword,
            kSecAttrService as String : Bundle.main.bundleIdentifier as AnyObject,
            kSecAttrGeneric as String : key as AnyObject,
            kSecAttrAccount as String : key as AnyObject
        ]
    }
    
    fileprivate func value(forKey key: String) throws -> Any {
        var query = commonConfigurationDictionary(forKey: key)
        query[kSecMatchLimit as String] = kSecMatchLimitOne
        query[kSecReturnData as String] = kCFBooleanTrue
        
        var result: AnyObject?
        let status = withUnsafeMutablePointer(to: &result) {
            SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0))
        }
        
        guard status != errSecItemNotFound else { throw WMFKeychainCredentialsError.noValue }

        return nil
    }
    
    private func setNewUUID(forKey key: String) {
        trySet(UUID().uuidString, forKey: key)
    }
    
    private func trySet(_ newValue: Any?, forKey key: String) {
        do {
            return try set(value: newValue, forKey: key)
        } catch  {
            assertionFailure("\(error)")
        }
    }
    
    fileprivate enum WMFKeychainCredentialsError: Error {
        case noValue
        case unexpectedData
        case couldNotDeleteData
        case unhandledError(status: OSStatus)
    }
    
    fileprivate func commonConfigurationDictionary(forKey key:String) -> [String : AnyObject] {
        return [
            kSecClass as String : kSecClassGenericPassword,
            kSecAttrService as String : Bundle.main.bundleIdentifier as AnyObject,
            kSecAttrGeneric as String : key as AnyObject,
            kSecAttrAccount as String : key as AnyObject
        ]
    }
    
    private func string(forKey key: String) throws -> String? {
        let queryDictionary = query(forKey: key) as CFDictionary
        
        var result: AnyObject?
        let status = withUnsafeMutablePointer(to: &result) {
            SecItemCopyMatching(queryDictionary, UnsafeMutablePointer($0))
        }
        
        guard status != errSecItemNotFound else { throw WMFKeychainCredentialsError.noValue }
