refactor tfidf method