nested query completed; tests to be improved