Yami - Retain State on Death - NoMethodError

When using Yami's "Retain State on Death" script (found here) the game seems to crash when a character dies while having a state that should not be retained on death. (In the attached example this state is MP Regen.)

The error message box says "Retain State on Death:87:in `block in die': undefined method `push' for nil:NilClass, NoMethodError"

I have attached a zip of only the data files of the example project, as recommended in this pinned thread.
There seems to be some odd behavior with 'inject'. Try replacing these original lines of code (Lines 85-88):
Code:
retains = states.inject([]) { |r, state|
      next unless state.retain_on_death?
      r.push([state.id, @state_turns[state.id], @state_steps[state.id]])
    }
with this new fix:
Code:
retains = states.inject([]) { |r, state|
      if state.retain_on_death?
        r.push([state.id, @state_turns[state.id], @state_steps[state.id]])
      end
      r
    }
That appears to work perfectly. Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/yami-retain-state-on-death-nomethoderror.82803/