Move keyword query building to separate file
Add query pretty printing

Closes #224.