It's probably something very simple but i tried to figure it out on my own without success.

So i am trying to fit a model into a basic shape like cube using the matchsize node. And i want to do it for multiple cubes. So i made it work with foreach connected piece, but there is a problem. The problem is that matchsize doesn't take the rotation of the cube into account. So what basically i am trying to do is to take the rotation of the cube before the matchsize and apply it to the result from the matchsize.

It's probably something very easy, but i am still learning the program, so any detailed explanation will be most welcome.
Thanks.