def _set_parameter(query_string, key, value):
    """
    Add a parameter to a query string if it's not there,
    Remove the parameter if it was already there
    """
    parameters = []
    already_there = False
    if query_string:
        for p in query_string.split('&'):
            k, v = p.split('=')
            if str(k) == str(key) and str(v) == str(value):
                already_there = True
            else:
                parameters.append('{0}={1}'.format(k, v))
    if not already_there:
        parameters.append('{0}={1}'.format(key, value))
    return '?%s' % '&'.join(parameters)