Decouple connection from group queries.

This way we can perform searches with groups easily.