refactor gen_generic