Finish the word substitution function