beginning of draft for frequency sort