Rewrote r_generator in Python.