replace_tail_inside