fixed tfidf and added distance function