small improvements in parseTemplate