add error exit
new template logic