Refactor sort by and pagination yet a bit