Fixed multiple category group support.

These changes also allow multiple category lookups to be performed with one query.