Implemented custom cosine-based distance with widf weighting