Support for nested queries (untested). Queries are const now.

A new construct allows for direct evaluation of a given callback
function as part of a query. The idea callback should evaluate the
nested query (wrt the original setup in the single-agent case, and wrt
some other setup in the multi-agent case). Not yet tested.

Also simplified the query rewriting and it's memory management, so that
queries const throughout the API.