refactor text replacement mechanism