refactory to generic template