Index Error: BMElemSeq[index]
# When your add/remove vert(s) in your mesh. You need add
bm.verts.ensure_lookup_table()
# to your code

# When your add/remove egde(s) in your mesh. You need add
bm.edges.ensure_lookup_table()
# to your code

# When your add/remove face(s) in your mesh. You need add
bm.faces.ensure_lookup_table()
# to your code