Added query handling