fixed some bugs with the shuffle function