fixed a bug in the shuffling function