generator_solution.py revamped and complete