Clean up Query and move stuff to QueryUtil

Closes #24.