At up to the Tang Dynasty, what is now Niujie would have been on the city's periphery according to archival research and historical documents. The Niujie Mosque was built between 916 and 1125. Wenfei Wang, Shangyi Zhou, and Cindy Fan stated that the establishment of the Hui settlement "probably" was related to Muslims joining the army of Genghis Khan, who had conquered Beijing, and that based on some gravestones of imams encountered at the Niujie Mosque, a significant community of Hui people had lived in the Niujie area dating back to the Yuan Dynasty. During that dynasty many Muslims moved to Beijing. Therefore, soldiers were the first Hui people in Niujie.