factorize template