start segment insertion code