Chapter 22: Battle with Cossacks, negotiations, and an agreement