fixed bug with sort order of query