implementing query handling