Instead of a nested array, how about making the sort function reference the frequency hash?