fixed incorrect clearing for templates