Implement sorting and limiting.