Added RNG and refactored some minor things.