Rewrite of findTriplets function and a quick hack for getting the most frequent tags