count and sort a collection