fixed restart bug, optimized randomization