Add comments to RNG implementation + additional error checking