Matrix rotation code