fixed bug in scan node query creation. also some half-baked changes to support aggregates and functions