Update sort handler to safely check for pagination or pager