improved the str_replace function