Yanfly's Damange Core - Making Enemies Despawn When Killed

I'm using Yanfly's Damage Core
http://yanfly.moe/2015/11/07/yep-25-damage-core/

I wrote the following code that allows me target an enemy to do damage, but then does random damage to 2 other enemies. The problem I am having is that if the enemy is killed by the damage to random enemy, they don't despawn. They will die as usual, and the battle will end if all die. But, the drawing is still there. Is there a line of code I should be adding here to say if the enemy dies, then despawn the drawing?

<damage formula>
value = 500
var blue = this.opponentsUnit().randomTarget();
blue.gainHp(-500);
blue.startDamagePopup();
var blue1 = this.opponentsUnit().randomTarget();
blue1.gainHp(-500);
blue1.startDamagePopup();
</damage formula>


Thanks in advance for any help.
Do an if check to see if the target has 0 HP, then use blue.performCollapse() to kill it.

Note that if you don't check their HP first, it will always kill the target, regardless of whether they had HP left or not.
Awesome, thanks!!

Here is the code I have that works. Is that the best way to use multiple if statements? Or is there a cleaner way to do it?
I'm thinking I may run out of space with more complex formulas or higher multi random hit skills.
[does the noteag box even have a character limit?]

<damage formula>
value = 500
var blue = this.opponentsUnit().randomTarget();
blue.gainHp(-25000);
blue.startDamagePopup();
if (blue.hp <= 0) {
blue.performCollapse()
};
target.gainMp(-20);
var blue1 = this.opponentsUnit().randomTarget();
blue1.gainHp(-25000);
blue1.startDamagePopup();
if (blue1.hp <= 0) {
blue1.performCollapse()
};
</damage formula>

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-damange-core-making-enemies-despawn-when-killed.87101/