simplify code by templated method