Add function count-similar
Fix a fatal bug in count-similar