Added replaceSubstring function