improve multi-level query handling