Added support for ad-hoc queries