Template replace logic, item condition checking, error handling
Refactoring, bugfixes