Add support for GROUP BY queries, fix issues when prologue does not match