First genchain function