Implement inner queries -- not yet perfect