A lot of code cleaning, and PRNG fixes