fixed up group by queries