Refactored the 'getMostFrequent' routine a few times.