Refactoring erase_substring and resize_elem.