Updated calculateSimilarity