bugs with max_seg_len fixed