Updated substiute function.