After Cao Cao's defeat, Liu Bei quickly took control of the majority of Jing Province. He then married Sun Quan's sister. Sun Quan then recognised the legitimacy of Liu Bei's control of the Jing Province and agreed to "lend" him Nan Commandery. Liu Bei later led his army to join another kinsman, Liu Zhang, in his war against the warlord Zhang Lu. Based on the advice of his advisors, Liu Bei betrayed Liu Zhang and seized the Yi Province from him. After engaging in a series of conflicts with Sun Quan and seeing Cao Cao's coming closer to the Yi province, Liu Bei agreed to yield half of the Jing province to Sun Quan and led his army against Xiahou Yuan at Hanzhong and seized it. Liu Bei then declared himself "King of Hanzhong" and set up his headquarters in Chengdu. However soon after hsi senior general Guan Yu was killed by Liu Bei's "ally" Sun Quan who took the rest of Jing province in return for having "lent" Liu Bei the Nan Commandery. Liu Bei was furious and after declaring himself emperor to challenge Cao Pi's authority, he led his army against his former ally. Though some early success, his army was soon forced into a stalemate against Sun Quan general Lu Xun and was subsequently defeated. Ashamed by his failure, he never returned to Chengdu and settled in Baidicheng where he lived until his death one year later. Urging his heir, eldest son, Liu Shan not to emulate him and rather be as virtuous as possible, before he died Liu Bei appointed Zhuge Liang to advise his son on domestic matters with Li Yan toi advise him on the military matters.