gen_fun: store terms in a set rather than in a vector