Cleaned up algorithm for shuffle to match that used in shuffle_slice