Updated according to Tobi's comments.

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