Refactor extracting distinct words from markdown document