Split Query class into QueryCLI and Query

Now it is possible to programmatically access the querying mechanism and
process its result without intermediate write into a file