Implementing solution for issue #32
Partial solution for issue #32 & fixing new issue with group by
Fixes issue #32