added sorting by frequency