Make query trace retrieving more reliable