moved rotating code after buffer swap, reducing cpu time considerably