Modified to simplify the generator logic.