Fix similarity calculation bug