Fixed bug in querying tool