added sorting to query