Little refactoring in the similarity function
Update tests