Updated rotation algorithm.