To simplify things, I updated the code to remove the rotation from the transformation matrix at the end of the animation.
However, to retain the right orientation of the cube, I bake the current rotation into the vertices.
I also rename the cube (as you did), but after the transformations explained above are applied, so that after the animation we end up with the exact same configuration of the Rubik than before the animation: same cube with same names at the same position, and not rotation (quaternion).
PG: