added query handling