Fix replace command bugs