Added frequency and sorting