updated querying code