Shuffle code and bug fixes