Conversion from maxscript ( coordsys transforms )

I’m trying to rewrite a 3ds Max script which imports an animation graph from Halo CE, I have a list of frame each having nodes transformations, being position, rotation ( quat ) and scale ( scalar ).
For what I understood, each node transform is relative to its parent, the maxscript code which imports these animation does this:

-- read frames
-- iterate each frame then node
rot = quat i j k -w
pos = x y z
scale = s s s    -- these are in frame[f][n]

addNewKey node.rotation.controller (f - 1)                                                                                                         at time (f - 1) 
(in coordsys parent node.rotation = rot)
-- and so on for position and scale

In blender side, I made a script that gets the frames ( I’m using a toolset in python made for Halo, MEK ),create an action and walks the pose bones tree:

# I build the frame's matrix
T = Matrix.Translation(frame.pos)
R = frame.rot.inverted().to_matrix().to_4x4()
S = Matrix.Scale(frame.scale, 4, (1,1,1))
M = T @ R @ S
if not node.parent:
    node.matrix = M
    node.matrix = node.parent.matrix @ M
# apply the fcurves using node's location, rotation_quaternion and scale

I came up to that after looking for coordsys explaination and a script that exports the animation graph from blender which multiply parent’s matrix inverse by the bone matrix.
The result though isn’t good, and Master Chief looks in pain.
The root bone is correctly animated.