Improve template geneartor