updated code for queries