New shuffle logic and code refactoring