Implementation of repeat and shuffle