I think you're correct but I think things are really complicated...with Mesbah Yazdi (Ahmadinejad's favorite Ayatollah) lobbying hard to replace Khamenei as Supreme Leader.
And remember that military plane crash last month(?) that had many Khamenei loyalist (senior IRGC officers) on board (and now dead).
My small brain aches trying to sort all this stuff out. I must be a masochist, because I thoroughly enjoy it.
Ahmadinejad (and Mesbah Yazdi for that matter) doesn't stand a chance if Rafsanjani and Khamenei want him (them) out of the picture.