Updated solution for multiple words.