Added sorting for getting queries.