refactored single fillTemplate() method