Fixed rotate function