fixed a bug with replace