use multimap instead of linear search