def convert(value, row):
    ori = key_as_str(row['aori'])
    state = get_state_key(row['astate'])
    
    if state == 'md':
        arrname = key_as_str(row['arrnamex'])
        if arrname in ('md recept diagno & class ctr f', 'md receipt diagno & class ctr f', 'reception center baltimore'):
            return 5
    
    elif state == 'ca':
        arrname = key_as_str(row['arrnamex'])
        if len(arrname) >= 5:
            if arrname[3:5] in ('pr', 'co', 'ho'):
                return 5
    
    elif state == 'la':
        try:
            return crosswalk['la'].convert(key_as_str(row['arrnamex']))
        except ConvertError:
            return value
        
    if len(ori) < 9:
        return value
    
    if state in ('il', 'id', 'nh', 'nd', 'ky', 'ut', 'wa', 'ok', 'wv', 'co', 'sc'):
        #if 9th position of ORI=C, nonarr=5
        if ori[8] == 'c':
            #TODO: verify that below if statement applies to all states (e.g. are some states exempted?)
            #CO exemptions
            if state == 'co' and key_as_str(row['arrnamex']).startswith('doc - criminal investigation division'):
                return value
            else:
                return 5
        elif state == "sc" and key_as_str(row['achglitx']).find("date of arrest not determined") != -1: 
            return 5
    
    elif state in ('nm', 'mn', 'ma', 'va'):
        #if 9th position of ORI=C or G, nonarr=5
        if ori[8] in ('c', 'g'): return 5
    
    elif state in ('vt', 'tx'):
        if ori[8] == 'g':
            return 5
        
    elif state == 'nv':
        #if 9th position of ORI=C and arrname != 'city of LV detention/enforcement', nonarr=5
        if ori[8] == 'c' and key_as_str(row['arrname']) != 'city of lv detention/enforcement': return 5
        
    elif state == 'nc':
        if ori[8] in ('c', 'g'): return 5
        if ori == 'nc060013y': return 4
    
    elif state == 'ia':
        if ori[8] in ('c', 'm') and key_as_str(row['arrname']) != 'dept of correctional services': 
            return 5
    
    return value