Ugly code to sort by frequency works!