added sorting of querying arrays