Support for GROUP BY and ORDER BY for queries

Also, added support for ORDER BY in collections.