 Fang continued to serve on Li Shimin's staff.In 621, when Li Shimin defeated Tang's major enemy Wang Shichong the Emperor of Zheng and captured the Zheng capital Luoyang (which had served as Sui's eastern capital), it was said that he sent Fang to the offices of Sui's legislative and examination bureaus of government to try to preserve Sui archives, but Fang's mission turned out to be unsuccessful as the archives had already been destroyed by Wang.Later in 621, when Emperor Gaozu, awarding Li Shimin for his great accomplishments, bestowed on him the unprecedented title of "Grand General of Heavenly Tactics" (天策上將, "Tiance Shangjiang"), Li Shimin built a mansion where he housed those staff members with the best literary talent, supplying them with the best food and supplies and had them conduct research and writing.