fixed bug in replace