def _modify_payloads(checks, values, clear):
    """
    Set or add payloads to checks.
    :param checks: list of check instance
    :param values: list of payloads with keys
    :param clear: boolean flag if clearing the predefined payloads
    :return: list of check instance
    """
    for key, payloads in values.items():
        for check in checks:
            if check.key == key:
                if clear:
                    check.set_payloads(payloads)
                else:
                    check.add_payloads(payloads)
    return checks