improve template.cpp