improve template parsing