Help me organize this python code.
def process_record(url, ann_type, sub_type):
    html = get_html(url)
    
    if html.find("strong"):
        aa = html.find("strong").text.strip() == "Amended Announcements"
    else: 
        aa = False

    ann_info = html.find("div", {"class": "ven_announcement_info"})
    sn = html_find(ann_info, "Stock Name ", subfix="H")
    date_ann = html_find(ann_info, "Date Announced", subfix="H")
    cat = html_find(ann_info, "Category", subfix="H")
    
    if ann_type=="SH%2CCHSH":
        if sub_type == "SH1%2CDRIC":
            tbs = html.find_all("table", {"class": "InputTable2"})
            sh = html_find(tbs[0], "Name")
            desc = html_find(tbs[0], "Descriptions(Class)") #no space
            noi = html_find(tbs[1], "Nature of interest")
            units = html_find(tbs[2], "Direct (units)")
    
        elif sub_type == "SH3%2CSSIC":
            tbs = html.find_all("table", {"class": "InputTable2"})
            sh = html_find(tbs[0], "Name").replace('\xa0', ' ')
            desc = html_find(tbs[0], "Descriptions (Class)") # have space
            noi = html_find(tbs[1], "Nature of interest")
            units = html_find(tbs[1], "Direct (units)")
    
        elif sub_type == "SH2%2CSSIN":
            tbs = html.find_all("table", {"class": "InputTable2"})
            sh = html_find(tbs[0], "Name").replace('\xa0', ' ')
            desc = html_find(tbs[0], "Descriptions (Class)")
            nrh = html_find(tbs[0], "Name of registered holder")
            date_chg = html_find(tbs[1], "Date interest acquired")
            nos = html_find(tbs[1], "No of securities")
            noi = html_find(tbs[1], "Nature of interest")
            units = html_find(tbs[1], "Direct (units)")
    
            tot = "Acquired"
            noi_sub = noi
            nrecords = 1
    
        elif sub_type == "SH4%2CSSIX":
            tbs = html.find_all("table", {"class": "InputTable2"})
            sh = html_find(tbs[0], "Name").replace('\xa0', ' ')
            desc = html_find(tbs[0], "Descriptions (Class)")
            nrh = html_find(tbs[0], "Name of registered holder")
            date_chg = html_find(tbs[0], "Date of cessation")
            nos = html_find(tbs[1], "No of securities disposed")
            noi = html_find(tbs[1], "Nature of interest")
    
            units = "CEASED"
            tot = "Disposed"
            noi_sub = noi
            nrecords = 1
        
        if (sub_type == "SH1%2CDRIC") or (sub_type == "SH3%2CSSIC"):
            ventb = html.find("table", {"class": "ven_table"})
            details = ventb.find_all("td", {"class":"formTableColumnLabel"})
            details = [data.text.strip() for data in details]
            
            nrecords = (len(
                ventb.find_all("td", string="Name of registered holder", 
                class_="formTableColumnHeader")))
            if nrecords == 1:
                date_chg = details[1]
                nos = details[2]
                tot = details[3]
                noi_sub = details[4]
                nrh = [details[5]] # one of the data must be a list
                
            elif nrecords > 1:
                date_chg = []
                nos = []
                tot=[]
                noi_sub = []
                nrh = []
                
                i = [key.text.strip() for key in ventb\
                     .find_all("td", {"class":"formTableColumnHeader"})]\
                    .index("Name of registered holder",6)
                for j in range(nrecords):
                    date_chg.append(details[1 + i*j])
                    nos.append(details[2 + i*j])
                    tot.append(details[3 + i*j])
                    noi_sub.append(details[4 + i*j])
                    nrh.append(details[5 + i*j])
        
    elif ann_type=="SB%2CSBBA":
        tb = html.find("table", {"class": "InputTable2"})
        desc = "Treasury Shares"
        noi = "N/A"
        units = "Treasury"
        noi_sub = "N/A"
        nrh = "N/A"
        
        if cat == "Immediate Announcement on Shares Buy Back":
            sh = "Shares Buy Back"
            tot = "B"
            date_chg = html_find(tb, "Date of buy back")
            nos = html_find(tb, "Total number of shares purchased (units)")
            
        elif cat=="Immediate Announcement of Changes in Treasury Shares":
            sh = "Treasury Shares Sold"
            tot = "S"
            date_chg = html_find(tb, "Date of transaction")
            nos = html_find(tb, "Total number of treasury shares changed (units)")
        
    data = {
        "ann_id": url[-7:],
        "name_ss": sh,
        '_class': desc,
        'noi': noi,
        'direct': units,
        'stock': sn,
        'date_ann': date_ann,
        'category': cat,
        'date_chg': date_chg,
        'nos': nos,
        'type': tot,
        'noi_sub': noi_sub,
        'name_rh': nrh,
        'amended': aa
    }
    
    if (sub_type == "SH1%2CDRIC") or (sub_type == "SH3%2CSSIC"):
        return pd.DataFrame(data)
    else:
        return pd.DataFrame([data])