break out query stuff into separate module