Added a function to select top n entries according to some keys