Upon returning to Poland in 1784, Kościuszko was commissioned as a major general in the Polish–Lithuanian Commonwealth Army in 1789. After the Polish–Russian War of 1792 resulted in the Commonwealth's Second Partition, he commanded an uprising against the Russian Empire in March 1794 until he was captured at the Battle of Maciejowice in October 1794. The defeat of the Kościuszko Uprising that November led to Poland's Third Partition in 1795, which ended the Commonwealth. In 1796, following the death of Tsaritsa Catherine II, Kościuszko was pardoned by her successor, Tsar Paul I, and he emigrated to the United States. A close friend of Thomas Jefferson's, with whom he shared ideals of human rights, Kościuszko wrote a will in 1798, dedicating his U.S. assets to the education and freedom of the U.S. slaves. Kościuszko eventually returned to Europe and lived in Switzerland until his death in 1817. The execution of his testament later proved difficult, and the funds were never used for the purpose Kościuszko intended.