refactored compute similarity map