Added group by queries
Fixed some more bad parameter exceptions