Refactored shuffling to be more efficient.