Pender freezes sometimes in Zero Sum

Hello everybody!
I’ve got a problem in Zero Sum when my hero freezes sometimes.
If I’m not mistaken it happens on casting raise-dead event.

def commandSelf():
    useMagic()
    engage()
    goldPickup()

def useMagic():
    ...
    if yeti:
        ...
    elif ...
    elif ...
    elif len(nearCorpses) > 3:
        if self.canCast("raise-dead"):
            self.cast("raise-dead")
        elif self.isReady("reset-cooldown"):
            self.resetCooldown("raise-dead")
            self.cast("raise-dead")
        return
    elif ...:
        self.cast("goldstorm")

I seems to me there is something strange with resetting the cooldown and then casting raise-dead.
But I can’t figure it out.

It seems to me that the problem is that the hero doesn’t have anything to do if raise-dead isn’t ready, and resetCooldown isn’t ready, but there are more then 3 corpses. You probably should include third option, or make else-if conditions so that they are true only if the hero can do something.