Fix and test the shuffle function.