 Fang served Li Shimin faithfully, and wherever Li Shimin campaigned, while his staff members would collect treasures, Fang spent the time interviewing the people of the area and retained the capable people to add to Li Shimin's staff.In 618, after news arrived at Chang'an (which Li Yuan had taken in winter 617 and where he declared Emperor Yang's grandson Yang You the Prince of Dai emperor (as Emperor Gong)) that Emperor Yang had been killed in a coup at Jiangdu (江都, in modern Yangzhou, Jiangsu), led by the general Yuwen Huaji, Li Yuan had Yang You yield the throne to him, establishing the Tang dynasty as its Emperor Gaozu.He created Li Shimin, the Prince of Qin.