implement function 'replace'