Refactored lib.templateparser