Make DebugQueryText generation more robust, and accurate