Code for flipping and rotating sets of related data