fix bug in multiple string replacement algorithm