Fixed bug in random number generator instatiation, moved to holding only a reference to the external RNG, various const and pass-by-reference fixes