OPT: improved template pre-processing