fix a bug in doreplace function