Added first query handling code