Help with Yanfly Actor Transformation Script

Ok first of all hooray for this coding, it works wonders except for a problem I'm having with it.

So my actors transform fine in battle and both stat boosts and appearance revert to normal once battle ends, but only if the actor is not KOed. If they are, they lose the stat boosts as planned but retain the transformed appearance which then becomes permanent.

What I want is for the actor's appearance and stats to revert to normal either when the battle is over or the actor is KOed by any possible methods (0 HP, instant death etc.)

It's worth mentioning that I have separate stat slots for every single character as all of their transformations are unique.

Can anyone help?

Original thread: https://forums.rpgmakerweb.com/threads/help-with-yanfly-actor-transformation-script.123672/