Review this code:

pub fn bed2gtf(input: &String, isoforms: &String, output: &String) -> Result<(), Box<dyn Error>> {
    msg();
    simple_logger::init_with_level(Level::Info)?;

    let start = Instant::now();

    let isf = reader(isoforms).unwrap_or_else(|_| {
        let message = format!("Isoforms file {} not found.", isoforms);
        panic!("{}", message);
    });
    let bed = bed_reader(input);
    let isoforms = get_isoforms(&isf);
    let gene_track = custom_par_parse(&bed).unwrap();
    let coords = combine_maps_par(&isoforms, &gene_track);
    let results: Vec<_> = bed
        .par_iter()
        .map(|record| to_gtf(&record, &isoforms))
        .collect();

    let flat_results: Vec<_> = results.into_iter().flatten().collect();
    let mut combined = [coords, flat_results].concat();

    combined.par_sort_unstable_by(|a, b| {
        let chr_cmp = compare(&a.0, &b.0);
        if chr_cmp == std::cmp::Ordering::Equal {
            a.2.cmp(&b.2)
        } else {
            chr_cmp
        }
    });

    let output = File::create(output).unwrap();
    let mut writer = BufWriter::new(output);
    comments(&mut writer);

    for (chrom, gene_type, start, end, strand, phase, attr) in combined {
        let gtf_line = format!(
            "{}\t{}\t{}\t{}\t{}\t.\t{}\t{}\t{}\n",
            chrom, SOURCE, gene_type, start, end, strand, phase, attr
        );
        writer.write_all(gtf_line.as_bytes()).unwrap();
    }

    let peak_mem = PEAK_ALLOC.peak_usage_as_mb();

    log::info!("Memory usage: {} MB", peak_mem);
    log::info!("Elapsed: {:.4?} secs", start.elapsed().as_secs_f32());

    Ok(())
}

fn to_gtf(
    bedline: &BedRecord,
    isoforms: &HashMap<String, String>,
) -> Vec<(String, String, u32, u32, String, String, String)> {
    let mut result: Vec<(String, String, u32, u32, String, String, String)> = Vec::new();
    let gene = isoforms.get(&bedline.name).unwrap_or_else(|| {
        let message = format!(
            "Isoform {} not found. Check your isoforms file",
            bedline.name
        );
        panic!("{}", message);
    });
    let fcodon = first_codon(bedline)
        .unwrap_or_else(|| panic!("No start codon found for {}.", bedline.name));
    let lcodon = last_codon(bedline).unwrap_or_else(|| {
        panic!("No stop codon found for {}.", bedline.name);
    });
    let first_utr_end = bedline.cds_start;
    let last_utr_start = bedline.cds_end;
    let frames = bedline.get_frames();

    let cds_end: u32 = if bedline.strand == "+" && codon_complete(&lcodon) {
        move_pos(bedline, lcodon.end, -3)
    } else {
        bedline.cds_end
    };

    let cds_start = if bedline.strand == "-" && codon_complete(&fcodon) {
        move_pos(bedline, fcodon.start, 3)
    } else {
        bedline.cds_start
    };

    build_gtf_line(
        bedline,
        gene,
        "transcript",
        bedline.tx_start,
        bedline.tx_end,
        3,
        -1,
        &mut result,
    );

    for i in 0..bedline.exon_count as usize {
        build_gtf_line(
            bedline,
            gene,
            "exon",
            bedline.exon_start[i],
            bedline.exon_end[i],
            3,
            i as i16,
            &mut result,
        );
        if cds_start < cds_end {
            write_features(
                i,
                bedline,
                gene,
                first_utr_end,
                cds_start,
                cds_end,
                last_utr_start,
                frames[i] as u32,
                &mut result,
            );
        }
    }

    if bedline.strand != "-" {
        if codon_complete(&fcodon) {
            write_codon(bedline, gene, "start_codon", fcodon, &mut result);
        }
        if codon_complete(&lcodon) {
            write_codon(bedline, gene, "stop_codon", lcodon, &mut result);
        }
    } else {
        if codon_complete(&lcodon) {
            write_codon(bedline, gene, "start_codon", lcodon, &mut result);
        }
        if codon_complete(&fcodon) {
            write_codon(bedline, gene, "stop_codon", fcodon, &mut result);
        }
    }

    result
}


If there is any improvement to make it more efficient or faster please implement it and give a description of all you have done