reorganised generator for simpler understanding