Clever way to rotate matrices