simplify code with template