added matrix rotation algorithm