Move gen_* functions out of Generator impl