Minor fixes and slightly perf. increase for random generation