fix a bug. The str should be checked before replacing