Improved tiles shuffling function.