(retrieve): Small refactor of order by code.