query 1 refactor + sort