Separate query into its own class

Fixes #12