implemented direct sorting