The port was upgraded to a "castrum" with the construction of a fortress by 890. It is unclear when exactly it was constituted the seat of a county, but it most likely occurred after 870, when there is evidence that the Hesbaye was divided into four counties. Numerous documents of the tenth and eleventh centuries describe locations as being in the district of Hesbaye in the county of Huy. The first identified count is the mysterious saint Mengold, killed in 892 and possibly a wholly legendary figure. According to the hagiographical "Vita Meingoldi comitis" (Life of Count Mengold), he was granted the county by the Emperor Arnulf. The documentation for the lay counts of Huy is sparse. Erenfrid, who held several counties, became the advocate of Stavelot by 943 and count of Huy shortly after. He was replaced as advocate in 965, but possibly as count of Huy as early as 964, when a certain Folcuin is first mentioned in documents, although he was not certainly count of Huy before 975. The relationships between the counts of Huy and how the countship may have been passed along by hereditary right have been studied by Donald C. Jackman. At some point during the reign of Otto I (c. 980), the bishop of Liège was granted the regalian rights of collecting the market tolls and minting coin. Shortly after 975, Ansfrid, the standard-bearer of King Otto I of Germany, was rewarded by Otto II with the county of Huy. His reputation as a count is provided by the chronicler Alpert of Metz, who states that he "investigated righteous legal decisions and spent so much time reading that he was mocked by some foolish people for living the life of a monk." He later entered the church, becoming bishop of Utrecht in 995 and dying in 1010. On 7 July 985, the possessions and jurisdiction of the county of Huy were transferred from the retiring Ansfrid to the diocese of Liège under bishop Notker. This grant is the beginning of the secular authority of the bishops of Liège and the county of Huy was thus the kernel of the prince-bishopric. In 1008, King Henry II augmented the grant with the royal forest in the county, which had been retained by the fisc in 985. The fortress of Huy became the chief refuge of the bishops of Liège.