Rotation algorithm implementation