Query tool

Review and merge.