bug fix and switch to do/while for prime_root shuffle