Decouple connection from groups queries.

This way we can perform searches with groups easily.