Improve template application