Correct implementation of rotate()