fixed error return in replace method