Added trace method for query debugging