Ratings counting

An extension of the previous version with added sorting.