Fixed sub-queries and added tests for nested sub-queries.