Added ability to handle inner selects