Fix bugs on selecting and replacing charaters