Localizing Ray not Possible?

So I’d like to transform a ray into local space. Current approach is:


I’m assuming the ray is now in local space, but apparently it’s not. Any idea why?
Also, I would also assume, transferring it back to global space would revert the values, but it does not:


→ New ray is completely different from initial ray. What’s the correct way to transform a ray into local space? (I assume normalizing the direction messes things up). Thank you

Solved with ray.applyMatrix4(mat.copy(object.matrixWorld).invert())

My mistake was applying the matrix to the 2 vectors individually, while it should be applied to the ray.