Optimize Queries

adding sorting constraints to database
simplifying queries
making other queries easier to read