add a frequency sorting function