improve usage of temp buffer in cigar string replacement