Even with the next move in mind, what else? Maybe Ke2, would have given the queen a spot to go to after Rf7. Re2? Doesn't save the queen if Rf7. Rf2, Rxf2.
26... Rf8g8 27. Qg1xg8 Kh8xg8
Wanting to keep the a8-h1 diagonal active.
28. Kf1e2
If the king were to stay on f1, then Qf3+ and Qg2++.
28... Bh1f3
A painful alternative, but a king's gotta do what a king's gotta do.
Because now if exf6+, Bxf6. White has to trade bishops or live with the pin. Which wouldn't be good, because if white tries to live with the pin, then Qxd2+. Then maybe just Qxa3 and black is still in great shape.
37. Rc1c2
This prevents such vicious plans, and prepares a discovered attack on the queen with knight's move. Now the f6 square is in some trouble.
37... Bh4e1 38. Nd2f3
It's possible for black to trade down to an advantageous endgame with Qxc2+. Kxc2, Bxc3. Kxc3... But the ending feels slow and uncertain, and with having a good attack going, it felt better to preserve pieces.
38... Be1xc3
A QNK,P5 vs RNK,P2 feels fine.
39. Kb2b3
The queen is still under attack, so white takes his king off of the dangerous rank before taking back the bishop.
39... Qh2h5
Maybe better would have been Qh1. This only ensures that white takes back with the rook rather than the king.