Updated according to Tobi's comments.

Cleaned up code, default GROUP_BY operator to a value of 0 if no value
specified.