Added the new way to handle RNGs.
Added test for new RNG handling.
Cleaned up code a bit.