Query refactoring. Better reprs, unit tests, and query inspection + shell integration (--query command)