fix bug in Q_template