add str_replace func and remove all memory leaks