Regen casts on dead allies

I am trying to cast regen on my allied soilders using this bit of code

     for(var s in soldiers){
        if(this.canCast('regen', soldiers[s]) && soldiers[s].health > 10){
            if(this.canCast('haste', soldiers[s])) this.castHaste(soldiers[s]);

Where soldiers is an array of allied units of type soldiers. This works great most of the time everyone once in a while it gets stuck on a dead soldier (which is not in the soldiers list) and endlessly case regen it. Also that dead soldier now has full life.

Followup: It seems to happen when she is casting on someone that dies while she is casting

Hmm, sounds funky, but I don’t immediately see the bug. Can you post the full code so I can out how the soldiers array is being made?