More fixing of $ issue

Use a function in the String.replace code that "flattens" the layout stack.