fixed the query to keep ordered results