simplify template function logic