better solution to guarav matrix rotation problem