added sorting in sql queries to make it easier to read on clients