Added group by, having. Reordered functions and properties.
Added a lot of comments, and hugely simplified order and group by
methods