Refactor with template structure