added support for sub queries